HTML - <label>

The HTML Label Element (<label>) represents a caption for an item in a user interface. It can be associated with a control either by placing the control element inside the <label> element, or by using the for attribute. Such a control is called the labeled control of the label element. One input can be associated with multiple labels.

Examples

Simple label example

HTML
<label>Click me <input type="text"></label>

Using the "for" attribute

HTML
<label for="username">Click me</label>
<input type="text" id="username">

Description  

The HTML Label Element (<label>) represents a caption for an item in a user interface. It can be associated with a control either by placing the control element inside the <label> element, or by using the for attribute. Such a control is called the labeled control of the label element. One input can be associated with multiple labels.

It's worth noting, however, that labels are not themselves directly associated with forms. They are only indirectly associated with forms through the controls with which they're associated.

Prior to a revision to the HTML specification made on April 28, 2016, the <label> element's form attribute allowed directly associating labels with forms.

Content categories Flow content, phrasing content, interactive content, form-associated element, palpable content.
Permitted content Phrasing content, but no descendant label elements. No labelable elements other than the labeled control are allowed.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parent elements Any element that accepts phrasing content.
DOM interface HTMLLabelElement

Browser Compatibility  

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes)[1] (Yes) (Yes) (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes)[1] (Yes) (Yes) (Yes)

[1] Starting with Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5), a bubbling click event triggers at most one <label>, and the synthetic click event cannot trigger additional <label>s. In Gecko, a click event will still bubble up past a <label>, while in WebKit or Internet Explorer the click event will stop at the <label>. The behavior prior to Gecko 8.0 (triggering multiple <label>s) caused Firefox to stop responding (see bug 646157).

[2] The HTML specification was updated in April 2016 to deprecate the form attribute. It's still available from script, but its definition has changed: it now returns the associated control's form, or null if there is no associated control (that is, if HTMLLabelElement.control is null). See HTMLLabelElement.form.

This change is implemented in Firefox 49.

See Also  

Specifications  

Specification Status Comment
WHATWG HTML Living Standard
The definition of '<label>' in that specification.
Living Standard  
HTML5
The definition of '<label>' in that specification.
Recommendation  
HTML 4.01 Specification
The definition of '<label>' in that specification.
Recommendation Initial definition

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/label

Element Forms HTML HTML forms Reference Web