Rule n° 69 - Each form field has its own label associated with it in the source code.
Not knowing what is a form field can be extremely confusing.
Goal
- Facilitate the understanding of the data expected in forms.
- Allow technical accessibility aids to render the fields in forms by systematically attaching a label to them, indicating their role and the nature of the expected input.
- Simplify input by allowing users to select the field by clicking on either its label or the field itself (especially in the case of a checkbox or a radio button).
- Improve the accessibility of content for people with disabilities.
Solution technique
Give each form field a label explicitly associated with it:
- if the label is visible, in the form of a
labelelement with aforattribute taking the value of theidattribute given to the field, for example:
<label for="nom1">Family name:</label>
<input id="nom1" type="text" name="nom">
- if the display of the image is not required (placeholder), in the form of an
aria-labelouaria-labelledby.
The use of a <label for="…"> label hidden by CSS styles is not recommended or aria-label ou aria-labelledby.
Moyen de contrôle
For each form field:
- Check, by looking at the source code or using Firebug, that the
forattribute, specific to thelabelelement, as well as theidattribute of the field have exactly the same content. If the values of these two attributes are identical, the (label) label is indeed associated with the (input) field. - If no label is visible in the site (placeholder), check that each form field has an
aria-labeloraria-labelledbyattribute.
In both cases, finally check that the label effectively describes the role of the field or the nature of the information that must be entered there. So this best practice cannot be automated but requires that each form is manually reviewed