Lesson 22 of 36
HTML Tutorial

Labels and Form Accessibility

Connect every control to a label, group related fields with fieldset and legend, and make forms usable for everyone.

3 min readBeginnerWeb FundamentalsHTML Forms

If one habit makes the biggest difference to your forms, it is this: label every control. A label tells people what to type, gives them a bigger click target and lets screen readers announce the field properly.

The label element#

There are two ways to associate a label with its input. The most reliable is the explicit for and id pair:

html
<label for="fullname">Full name</label>
<input type="text" id="fullname" name="fullname">

The label's for must equal the input's id. Now clicking the label text focuses the field, and a screen reader says "Full name, edit text".

You can also wrap the control inside the label, which needs no ids:

html
<label>
  Full name
  <input type="text" name="fullname">
</label>

Both are valid. Many teams use the explicit version because it allows more flexible layouts.

Help text and errors#

Use aria-describedby to link a field to extra guidance, so it is read out after the label:

html
<label for="pickup">Pickup name</label>
<input type="text" id="pickup" name="pickup" aria-describedby="pickup-hint" required>
<p id="pickup-hint">We will call this name when your order is ready.</p>

Place error messages near the field and link them the same way. Describe how to fix the problem ("Enter an email such as name@example.com") rather than only saying "Invalid".

Grouping with fieldset and legend#

When several controls belong together, wrap them in <fieldset> and give the group a name with <legend>. This is essential for radio buttons and checkboxes, where the question applies to all options.

html
<fieldset>
  <legend>Preferred pickup time</legend>

  <label>
    <input type="radio" name="pickup_time" value="morning">
    Morning
  </label>
  <label>
    <input type="radio" name="pickup_time" value="afternoon">
    Afternoon
  </label>
</fieldset>

A screen reader announces the legend along with each option: "Preferred pickup time, Morning, radio button". Without it, the options would lack context. Browsers draw a border around a fieldset by default; style it away with CSS if you wish.

Other accessibility essentials#

  • Tab order: controls should be reachable in a logical order with the Tab key. Keep the source order matching the visual order.
  • Visible focus: never remove the focus outline without providing a clear replacement.
  • Mark required fields: use the required attribute and say so in the label, for example "Email (required)". Do not rely on colour alone.
  • Autocomplete tokens: autocomplete="name", "email" and "tel" help many users, particularly those with motor or cognitive difficulties.
  • Buttons: use a real <button> with clear text, such as "Send message", not "Submit".

Common mistakes#

  • Missing for and id links, so the label is just text.
  • Duplicating an id on the page, which breaks the association.
  • Using placeholders as the only labels.
  • Grouping radios without a legend.
  • Using only red text to signal errors.

Try it yourself#

Take any form you have written and audit it. Click every label: does the field focus? Add fieldset and legend to any radio group. Add a hint paragraph linked with aria-describedby. Then put your mouse aside and fill in the whole form using only the keyboard, making sure focus is always visible.

Recap#

Every control needs an associated label, via for and id or by wrapping. Use fieldset and legend for groups, link help text with aria-describedby, and test with the keyboard. Placeholders never replace labels.

Check your understanding

Lesson quiz

Optional

A short quiz to check what you just learned.

Questions
4
Time limit
5 min
Pass mark
70%
Best score
-