Sub topic 2
Labels: every control needs a visible, associated label
This chapter assumes you know basic HTML form elements (form, input, button), can style text and spacing with CSS, and have seen the id attribute. You don't need JavaScript here.
A label tells the user what a field is for. Two properties make a label work: it is visible, so anyone can read it at any time, and it is associated, so the browser and assistive technology know which control it describes. Missing either one is the most common cause of forms that are hard to use.
Why both properties matter
A visible label that is not associated looks fine on screen. A screen reader user who tabs into the field hears only "edit text" with no name. Clicking the label does nothing, which leaves a small click target.
An associated label that is not visible, such as one hidden with aria-label or display: none, names the control for assistive technology. Sighted users, though, get no stable cue. Users with memory or attention difficulties lose context. Speech-control users can't say the name of a control they can't see.
The browser computes an accessible name for every control. Assistive technology reads that name aloud and uses it for voice commands such as "click Email address". A visible, associated label is the most reliable way to supply it.
The label element with for and id
The standard pattern pairs a label element with a control. The label's for attribute must match the control's id.
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required>This gives you three things:
- A screen reader announces "Email address, edit text" when the field gets focus.
- Clicking or tapping the label text moves focus to the input. For checkboxes and radio buttons, it toggles them, which enlarges the target.
- Voice control software can activate the field by the label's text.
Note that id and name do different jobs. The id links the label to the control and must be unique on the page. The name is the key the browser sends to the server with the value.
Wrapping as an alternative
You can also place the control inside the label. No for or id is needed.
<label>
Email address
<input name="email" type="email" autocomplete="email" required>
</label>This works in browsers, but some assistive technology and voice-control tools have handled it less reliably than explicit for/id pairs. It also makes layout harder, because the label text and control share one parent. The explicit pair is the safer default, and you can use both together if you want the wrapper for styling.
What a good label says
Write labels as short noun phrases that name the data. Use the words your users use.
| Weak label | Better label | Reason |
|---|---|---|
| Enter here | Email address | Says nothing about the data |
| DOB | Date of birth | Abbreviation may be unclear |
| Name | Full name (or Given name and Family name) | Removes doubt about what to enter |
| Phone? | Mobile phone number | Not a question; states the exact data |
| Click to choose | Country | Describes the action, not the field |
Keep each label unique on the page when the fields mean different things. Two fields both labeled "Address" in separate sections confuse screen reader users who navigate by a list of form controls. If the repetition is unavoidable, group the fields (a later chapter covers fieldset and legend) or make the labels distinct, for example "Billing address line 1".
Put the label text in the label itself. Don't rely on surrounding text, such as a table heading or a paragraph above, to explain the field.
Controls that need labels
Every control the user can interact with needs a label, not only text inputs:
inputof any type excepthiddenandsubmit/button/reset/image, which get their name fromvalueoralt.selecttextarea- Custom widgets built from other elements, which need an accessible name through
aria-labelledbyoraria-label, plus the right role.
Checkboxes and radio buttons each need their own label. A group of them also needs a shared question, which fieldset and legend provide.
<input type="checkbox" id="newsletter" name="newsletter">
<label for="newsletter">Send me the monthly newsletter</label>For a select, the label sits outside the element, just like an input:
<label for="country">Country</label>
<select id="country" name="country" autocomplete="country-name">
<option value="">Choose a country</option>
<option value="gb">United Kingdom</option>
<option value="us">United States</option>
</select>Common errors
These mistakes appear in real code reviews.
- Mismatched
forandid. A typo such asfor="e-mail"againstid="email"silently breaks the link. Nothing is reported in the page. - Duplicate
idvalues. If two inputs shareid="name", the label attaches to the first one only. This often happens when a form component is rendered twice on one page. - Placeholder as the only label. The placeholder disappears once the user types, and it often has low contrast. It is not a reliable accessible name. A later chapter treats this in detail.
- A label that is not a
label. Adivorspanstyled to look like a label has no association. - Hidden labels as a design shortcut. Removing visible labels to make a form look cleaner trades usability for appearance.
- Interactive content inside a label. Putting a link inside a label makes clicks ambiguous: the user may navigate away instead of focusing the field. Keep links in hint text instead.
A short note on aria-label and aria-labelledby
ARIA attributes can supply an accessible name when no native label is possible.
aria-labelledby="id1 id2"points to existing visible text and builds the name from it.aria-label="Search"supplies a name as a string that no one sees.
The first rule of ARIA is to use native HTML when it does the job. A label with for gives you the name, the larger click target, and broad support. Reserve aria-label for cases with a real reason, such as a search field next to a clearly labeled magnifier button. Even then, a visible label is usually better.
How to check a label
You can verify labels without special tools.
- Click the label text. Focus should move to the control, or the checkbox should toggle.
- Open your browser's accessibility inspector and select the control. The "Name" property should show your label text.
- Tab through the form with a screen reader running. Each control should be announced with its label and type.
- Run an automated checker. It catches missing labels and duplicate IDs, though it can't judge whether the wording is clear.
The diagram below shows how the pieces connect.
Summary of the rule
For each control: write a visible label, connect it with a matching for and id, use plain wording that names the data, and confirm that clicking the label focuses the field. Everything else about labels, including placement and hint text, builds on this base.
Exercise
A teammate's form has <label>Phone number</label><input id="phone" type="tel">. A screen reader announces only "edit text", and clicking the label text does nothing. What is wrong, and how do you fix it? Name one other mistake that would produce the same symptom.
Show answer
The label has no for attribute, so it is not associated with the input. Fix it with <label for="phone">Phone number</label>. The same symptom appears if for and id don't match exactly (for example for="telephone" against id="phone") or if two controls on the page share the same id.
Exercise
A designer proposes removing the visible labels from a three-field sign-up form and using aria-label on each input to keep the screen reader experience intact. Give two reasons a visible, associated label is still better.
Show answer
Any two of these: the label stays visible after the user types, so people can check what they entered; users with memory or attention difficulties keep their context; speech-control users can see the name they need to say; a label enlarges the click target, while aria-label does not; and a native label has broader support than a string that no one sees.