HTML Labels: Accessible Names for Form Controls
Explicit labels
Set for on the label to the control’s unique id. Clicking the text focuses the associated text control. The name used for submission is independent of the id.
<label for="full-name">Full name</label><input id="full-name" name="person" type="text">The field is named Full name for accessibility; its submission key is person.
Wrapping a control
A label can contain the control it labels. For a simple input this avoids the need for a separate for/id pair. Include one intended labelable control; do not place unrelated interactive controls in the label.
<label> Library card <input name="card" type="text"></label>Clicking Library card focuses its input.
A label plus a hint
Keep a label visible after text is entered. A placeholder can illustrate the expected format, while the label states the purpose. A blank field is still labeled even if its placeholder disappears.
<label for="room">Room number</label><input id="room" name="room" placeholder="e.g. B12">Room number is the visible label; e.g. B12 is a hint.
Common mistakes and practice
Every text entry needs a meaningful visible label. A placeholder is a short hint, not a durable label. Do not reuse IDs; a matching for value must identify the intended labelable element. Practice labeling a room-number field without relying on a placeholder.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Labels: Accessible Names for Form Controls — Knowledge Check
Apply the form-control concepts from this lesson.
What must label for="city" match?
Which approach keeps the field purpose visible while typing?
Which attribute supplies the submission key?
Which markup implicitly associates a label with its control?
Why should IDs used by explicit labels be unique?