Why it matters
- A label tells everyone what a field is for, and screen readers read it when the field gets focus. Text placed near a field without being tied to it, such as a paragraph above it, is not read with it.
- Clicking a label also moves to its field, a larger target on a phone.
- WCAG 2.2 asks that every control has a name that assistive technology can read (success criterion 4.1.2, level A).
Example
<p>البريد الإلكتروني</p> <input id="email" name="email" type="email" autocomplete="email" />
<label for="email">البريد الإلكتروني</label> <input id="email" name="email" type="email" autocomplete="email" />
How to fix
- Tie a
<label>to the field:<label for="email">البريد الإلكتروني</label> <input id="email" type="email">, or put the field inside its label. - For a field without visible text, such as a search box, give it
aria-label="ابحث في المتجر".
How we detect
- We render the page and run axe-core 4.13.0's
labelrule in each engine. - It reports each input and textarea without an accessible name: no label,
aria-label,aria-labelledby,titleor placeholder. axe accepts a placeholder as a name; it disappears as someone types, so a visible label is still better. Drop-down lists (<select>) are a different axe rule,select-name, which Arablyzer reads too. - It does not apply to pages without form fields.