HTML label element

Reference for the HTML label element: matching for and id, labelable controls, and why a label must not wrap more than one interactive control.

The label element captions a form control and associates that caption with the control. This page deepens the catalog card for <label>. The form and input pages already use labels in examples; this page explains the association rules instead of repeating those type lists.

Both start and end tags are required. Permitted content is phrasing content, with the important restriction that a label must not contain more than one of its labeled-control descendants, and it must not contain other interactive content that is not the labeled control. The labeled control must be a labelable element: button, input except type="hidden", meter, output, progress, select, and textarea.

Examples are complete local forms with no third-party action. They were checked with Python 3.13's html.parser as a structural tree, and with the site build. Activation, focus, and assistive-technology behavior were not tested in a user agent.

Official sources: MDN <label> element and the WHATWG HTML Living Standard. Fragments were checked with Python 3.13 html.parser. That parser builds an element tree; it is not a WHATWG conformance checker, and this is not a browser or accessibility test.

HTML tag catalog → · HTML tutorial overview →

for, id, and labelable elements

When the for attribute is present, its value must match the id of a labelable element in the same tree. That element is the labeled control, even if it is not a descendant of the label. The association is with id, not with name.

The first example uses an explicit for and id pair, which is the usual pattern when the caption and the control are siblings. Clicking or activating the label is specified to activate the associated control; that activation was not performed here.

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.

AttributeDescription
forThe 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.
html
<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

MDN documentation → · WHATWG HTML Standard →

Wrapping a control, and what not to nest

If for is omitted, the labeled control is the first labelable descendant of the label. Wrapping a single checkbox or radio button, including its caption text, is a common pattern. Several label elements may refer to the same control.

Do not put two labelable controls inside one label. Do not nest a label inside another label. Do not mix a link, button, or second input with the labeled control inside the same label. Those patterns are invalid or ambiguous and are described here rather than shown as examples to copy.

A label that wraps one checkbox, not several interactive controls

<label>
  <input type="checkbox" name>
  Caption
</label>

With no for attribute, the first labelable descendant is the labeled control. The label contains only that one control.

AttributeDescription
forOmitted in this example so the association comes from the descendant input, not from an id match.
  • The label contains one labelable descendant and no other interactive content. A second input or a link inside the same label is not included on purpose.
html
<form>
  <label>
    <input type="checkbox" name="subscribe" value="1">
    Email me a practice summary
  </label>
  <button type="submit">Save preference</button>
</form>

What this markup means

The checkbox is the only labelable descendant, so it is the labeled control even without a for attribute. The caption text sits beside that one input. The submit button is a sibling of the label, not a second control inside it. Activation was not tested here.

Related: Tag catalog: <label>, <input>, <select>, <textarea>

MDN documentation → · WHATWG HTML Standard →