The <label>
represents a caption for an item in a user interface.
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 parents | Any element that accepts phrasing content. |
Permitted ARIA roles | None |
DOM interface | HTMLLabelElement |
This element includes the global attributes.
for
id
of a labelable form-related element in the same document as the label element. The first such element in the document with an ID matching the value of the for
attribute is the labeled control for this label element.for
attribute and a contained control element, as long as the for
attribute points to the contained control element.form
HTML5
<form>
element in the same document. This lets you place label elements anywhere within a document, not just as descendants of their form elements.HTMLLabelElement.form
attribute; it returns the form of which the label's associated control is a member, or null
if the label is not associated with a control or the control isn't part of a form.<label>
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.<label>
is clicked or tapped, and it is associated with a form control, the resulting click
event is also raised for the associated control. <label>Click me <input type="text"></label>
<label for="username">Click me</label> <input type="text" id="username">
Specification | Status | Comment |
---|---|---|
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 |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | Yes | Yes | Yes |
for |
Yes | Yes | Yes | Yes | Yes | Yes |
form |
Yes | Yes | Yes — 49 | Yes | Yes | Yes |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | Yes | Yes | Yes | ? |
for |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
form |
Yes | Yes | Yes | Yes — 49 | Yes | Yes | ? |
<form>
, <input>
, <button>
, <datalist>
, <legend>
, <select>
, <optgroup>
, <option>
, <textarea>
, <keygen>
, <fieldset>
, <output>
, <progress>
and <meter>
.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label