Summary
Ensure all form inputs and custom controls have labels that clearly describe their purpose.
Techniques
-
Label form inputs. [[WCAG-3.3.2]]
-
Provide instructions for expected values. [[WCAG-3.3.2]]
-
Provide labels for individual controls. [[WCAG-4.1.2]]
-
Provide labels for groups of controls. [[WCAG-4.1.2]]
Examples
Explanation
Providing an accessible name for form inputs and custom scripted controls is essential for ensuring that users can understand their purpose. Assistive technologies compute the name for each control when a label is provided allowing users to quickly discover the purpose of each.
Due to the way that forms are laid out, however, users often reach input fields before the labels that describes them, or the labels may occur well before the field. If a label is not provided, the experience of interacting with dynamic content or filling out a form can be confusing.
HTML provides two native elements for associating labels with controls:
-
label
-
The
label
element is used to identify the accessible name for an individual control. It can either be wrapped around the control and its label (see Example 1) or afor
attribute can be added that references the ID of the control (see Example 1). -
fieldset
-
The
fieldset
element is used to group sets of related controls. A label can then be provided in a childlegend
element (see Example 3).
There are two drawbacks to these native methods: one is that they only accept a single label and the
other is that the labels must be a visible part of the page and the text can be capture by the
label
element. The following ARIA attributes help solve these more complex cases:
-
aria-labelledby
-
The
aria-labelledby
attribute can be used to reference multiple elements. It is useful when more than one piece of information is necessary to give full context to a control (see Example 5). It can also be used to identify the label when it is not possible to use alabel
element (see Example 4). -
aria-label
-
The
aria-label
attribute can be used when it is not possible to include a label by any other means (see Example 6). The value of the attribute is the label for the control.
Related Links
- HTML — The
label
element - HTML — The
fieldset
element - ARIA — aria-label (property)
- ARIA — aria-labelledby (property)