Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 38 ยท Forms and Dynamic Content

Accessible Form Labels and Instructions

Build accessible forms: visible labels, fieldset and legend, hints with aria-describedby, required fields, autocomplete tokens and target size, with live demos.

Forms are where people buy, apply, book and sign in. They are also where inaccessible pages fail hardest, because a form that cannot be completed is a closed door. Most form problems come from the same small set of mistakes: missing labels, unclear instructions, and controls built from non-form elements.

This lesson covers the labeling and structure of fields. The next lesson handles errors and validation.

Every control needs a label

Success criteria 1.3.1 (info and relationships), 3.3.2 (labels or instructions) and 4.1.2 (name, role, value) all point to one rule: each input has a programmatically associated, visible label.

HTML
<label for="city">City</label>
<input id="city" name="city" type="text">

The for attribute must match the input's id. Clicking the label focuses the input, which also enlarges the click target. You can also wrap the input:

HTML
<label>City <input name="city" type="text"></label>

Explicit for/id pairing is the most robust, especially with some screen reader and voice-control combinations.

Placeholders are not labels. Placeholder text disappears as soon as someone types, usually has low contrast, and is not reliably announced. Use it only for an example, never for the field's name.

Label or placeholder

Hidden labels (only when design demands it)

A search box next to a magnifier button can look fine without a visible label. If you must hide it, hide it visually with the .sr-only pattern, or use aria-label:

HTML
<input type="search" aria-label="Search the site">

A visible label is still better: it helps people with cognitive disabilities and everyone using voice commands ("click Search").

Grouping with fieldset and legend

Radio buttons and related checkboxes need a group label as well as individual labels. <fieldset> and <legend> provide it.

HTML
<fieldset>
  <legend>Preferred contact method</legend>
  <label><input type="radio" name="c" value="email"> Email</label>
  <label><input type="radio" name="c" value="phone"> Phone</label>
</fieldset>

A screen reader says "Preferred contact method, group. Email, radio button, 1 of 2". Without the legend, users hear only "Email" and lose the question. Use fieldsets for address blocks and date triples too.

Hints and instructions

Put instructions before the field and connect them with aria-describedby, so they are read after the label:

HTML
<label for="pw">Password</label>
<p id="pw-hint">At least 12 characters. Spaces are allowed.</p>
<input id="pw" type="password" aria-describedby="pw-hint" autocomplete="new-password">

Tell people about formats (dates, phone numbers) up front, not only after they fail. Keep hints visible; tooltips that appear on hover are hard to reach by keyboard or touch.

Required fields

Use the native required attribute (it also adds validation), and say so in text.

HTML
<p>Fields marked <strong>(required)</strong> must be filled in.</p>
<label for="em">Email <span>(required)</span></label>
<input id="em" type="email" required autocomplete="email">

If most fields are required, flip it and mark the optional ones. An asterisk is fine if the form starts with an explanation of what it means; add aria-hidden="true" to the asterisk because required already announces the state.

Input purpose with autocomplete

1.3.5 Identify Input Purpose (AA): fields that collect personal data must declare their purpose so browsers and assistive tools can autofill or show icons. Use the standard autocomplete tokens.

Field Token
Full name name
Given / family name given-name, family-name
Email email
Telephone tel
Street address street-address
Postal code postal-code
Country country-name
Current password current-password
New password new-password
One-time code one-time-code

Autofill saves typing for people with motor and memory difficulties. Also pick the right type (email, tel, url, number only for real quantities) so mobile keyboards adapt; use inputmode for fine tuning.

A well-labeled mini form

More rules of thumb

  • Put the label above the field on small screens; a left label wastes width and breaks at zoom.
  • Make buttons real <button> elements with clear names ("Create account", not "Submit").
  • Group long forms into steps with headings, and say where the user is ("Step 2 of 4").
  • 3.3.7 Redundant Entry (A, WCAG 2.2): do not ask users to retype information they already gave in the same process, for example a billing address that equals the shipping address.
  • Give controls at least 24 by 24 CSS px, ideally 44 by 44 for touch.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which markup gives an input a programmatic label?

    A label whose for matches the input's id creates the association screen readers and voice control rely on.
  2. 2. What do fieldset and legend provide?

    The legend is announced as the group's name, which gives radio buttons their question.
  3. 3. How do you connect a hint to its input?

    aria-describedby makes assistive technology read the hint after the label and role.
  4. 4. Which attribute helps browsers autofill an email field and satisfies 1.3.5?

    The autocomplete token states the purpose of the field in a standard, machine-readable way.

Summary

  • Every field needs a visible, programmatically associated label; placeholders are only examples.
  • Use fieldset and legend for groups, aria-describedby for hints, and required plus text for mandatory fields.
  • Add autocomplete tokens and appropriate input types.
  • Avoid asking for the same data twice and keep targets large.

Next: Form Errors and Validation