<label> (Form Control Label)
This HTML 4 element is used to relate descriptions to form controls.
Standard Syntax
<label
accesskey="key"</label>
class="class name(s)"
dir="ltr | rtl"
for="id of form field"
id="unique alphanumeric identifier"
lang="language code"
style="style information"
Attributes Defined by Internet Explorer
contenteditable="false | true | inherit" (5.5)
datafld="column name" (4)
dataformatas="html | text" (4)
datasrc="data source id" (4)
disabled="false | true" (5.5)
hidefocus="true | false" (5.5)
language="javascript | jscript | vbs | vbscript" (4)
tabindex="number" (5.5)
unselectable="on | off" (5.5)
Standard Event Attributes
onblur, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup
Events Defined by Internet Explorer
onactivate, onafterupdate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onbeforeupdate, onblur, oncontextmenu, oncontrolselect, oncut, ondeactivate, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerrorupdate, onfocus, onfocusin, onfocusout, onhelp, onlosecapture, onmouseenter, onmouseleave, onmouseup, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresize, onresizeend, onresizestart, onselectstart
Element Specific Attributes
- accesskey
- This attribute specifies a keyboard navigation accelerator for the element. Pressing ALT or a similar key in association with the specified key selects the anchor element correlated with that key.
- datafld
- This attribute is used to indicate the column name in the data source that is bound to the content of the <label> element.
- dataformatas
- This attribute indicates whether the bound data is plain text (text) or HTML (html). The data bound with <label> is used to set the content of the label.
- datasrc
- The value of this attribute is an identifier indicating the data source to pull data from.
- for
- This attribute specifies the id for the form control element the label references. This is optional when the label encloses the form control it is bound to. In many cases, particularly when a table is used to structure the form, the <label> element will not be able to enclose the associated form control, so the for attribute should be used. This attribute allows more than one label to be associated with the same control by creating multiple references.
Examples
<form>
<label id="usernamelabel">Name
<input type="text" id="username">
</label>
</form>
<form>
<table>
<tr>
<td><label for="username">Name</label></td>
<td><input type="text" id="username"></td>
</tr>
</table>
</form>
Compatibility
HTML 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 4, 5, 5.5, 6
Netscape 6, 7
Opera 4-7
Notes
Each <label> must not contain more than one form field.
The label element should not be nested.