Deze vertaling is niet volledig. Help dit artikel te vertalen vanuit het Engels.
Het HTML-label-element (<label>
) stelt een bijschrift van een element in een gebruikersinterface voor. Een label kan met een element geassocieerd zijn doordat het element in het <label>
-element staat, of door middel van het attribuut for
. Dit element heet het gelabelde element van het label. Eén input-element kan geassocieerd zijn met meerdere labels.
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 |
Attributen
This element includes the global attributes.
accesskey
HTML 4 HTML5- A shortcut key to access this element from the keyboard.
for
- The 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.Note: A label element can have both afor
attribute and a contained control element, as long as thefor
attribute points to the contained control element. form
HTML5- The form element that the label element is associated with (its form owner). If specified, the value of the attribute must be the ID of a
<form>
element in the same document. This attribute enables you to place label elements anywhere within a document, not just as descendants of their form elements.
Voorbeelden
Eenvoudig voorbeeld-label
<label>Click me <input type="text"></label>
Met het "for"-attribuut
<label for="username">Click me</label> <input type="text" id="username">
Specificaties
Specificatie | Status | Opmerking |
---|---|---|
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 | Oorspronkelijke definitie |
Browser-compatibiliteit
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).
Zie ook
- Andere elementen die te maken hebben met formulieren:
<form>
,<button>
,<datalist>
,<legend>
,<select>
,<optgroup>
,<option>
,<textarea>
,<keygen>
,<fieldset>
,<output>
,<progress>
en<meter>
.