A label whose for matches a labelable control's id
<label for="id">Caption</label>
<input id="id">for points at the id of a labelable element in the same document, not at the control's name.
| Attribute | Description |
|---|---|
for | The id of the labeled control. The value must match a labelable element's id in the same tree. It is not the control's name. |
- The input is type=text, which is labelable. A hidden input is not labelable and must not be the labeled control.
<form>
<label for="title">Title</label>
<input id="title" name="title" type="text">
<button type="submit">Save title</button>
</form>What this markup means
The label's for="title" matches the input's id="title". The name attribute is only the submitted field name. If for and id disagreed, the caption would not be associated with that input. The form has no remote action, and the label was not clicked here.
Related: Tag catalog: <label>, <form>, <input>, HTML tutorial: Label a form