Form Instructions
Provide instructions to help users understand how to complete the form and use individual form controls. Indicate any required and optional input, data formats, and other relevant information.
Important: Screen readers often switch to “Forms Mode” when they are processing content within a <form>
element. In this mode they usually only read aloud form elements such as <input>
, <select>
, <textarea>
, <legend>
, and <label>
. It is critical to include form instructions in ways that can be read aloud. This will be explained further below.
Overall instructions
Where relevant, provide overall instructions that apply to the entire form. For example, indicate any required and optional input, allowed data formats, and timing limitations. Provide such instructions before the <form>
element to ensure that it is read aloud by screen readers before they switch to “Forms Mode”.
In the example below, form instructions indicate how required fields are marked, the expected format for the main data fields, and where to find additional help for each input.
In-line instructions
In addition to overall instructions, it is also important to provide relevant instructions within the labels of the form controls. For example, to indicate required input fields and data formats in the text of the labels.
Providing instructions within labels
For simple use cases, providing instructions within labels may be sufficient. This approach is reliable across different web browsers and assistive technologies, although it may require some additional thought to support some styling needs.
In the example below, the required format for the “Expiration Date” is indicated by “MM/YYYY” within the same label:
Providing instructions outside labels
Providing instructions outside of labels allows more flexible positioning and design, but sometimes it can be missed. It is also not supported by some web browsers (typically older versions) and assistive technologies that don’t implement WAI-ARIA.
Using aria-labelledby
One approach is to use the WAI-ARIA aria-labelledby
attribute to associate instructions with form controls. At the time of writing this tutorial, this approach is not fully supported by all web browsers and assistive technologies, for example, Braille displays. To ensure backward compatibility, the for
and id
attributes are also used in this example.
Using aria-describedby
Another apporach to associate additional instructions with a form field is to use aria-describedby
. Information referenced by this attribute is made available to the users after the label and other information is announced.
Placeholder text
Placeholder text provides instructions or an example of the required data format inside form fields that have not yet been edited by the user. Placeholder text is usually displayed with lower color contrast than text provided by users, and it disappears from form fields when users start entering text. If the placeholder text contains instructional information or examples that disappear, it makes it more difficult for users to check their responses before submitting the form.
While placeholder text provides valuable guidance for many users, placeholder text is not a replacement for labels. Assistive technologies, such as screen readers, do not treat placeholder text as labels. Moreover, at the time of writing this tutorial, placeholder text is not broadly supported across assistive technologies and not displayed in older web browsers.
Note: Section Hidden labels of this tutorial describes how to hide information visually but keep it available to assistive technology. This same approach can be used to avoid visual redundancy of displaying both labels and placeholder text. Be aware that this makes it very hard for users to review the form. To avoid this problem, JavaScript can be used to make labels appear visually (in the associated label element) above or beside the input that has focus.
Styling
At the time of writing this tutorial, web browsers usually display the placeholder text in a color that does not meet the minimum contrast requirement of WCAG. This means they are hard to see for many people. Web browsers use a combination of color and opacity to achieve this effect. In most web browsers the color of the placeholder can be styled using proprietary CSS selectors. The following code snippet sets the color to a light gray, which has just enough contrast to meet the contrast requirement, assuming the background of the element is white.
Back to Top