This <label> element creates a label and associates it with another element on the page. The element to which the label is linked must contain the id attribute.
When giving the accesskey attribute of the <label> element a value, pressing ALT and the access key will set the focus on the linked element.
<label> |
Yes | Yes | Yes | Yes | Yes |
The "form" attribute is new in HTML5.
Attribute | Value | Description |
---|---|---|
for | element_id | Set the owner id |
form | form_id | Set the owner form the label belongs to |
The <label> tag supports the Global Attributes in HTML.
The <label> tag supports the Event Attributes in HTML.
label {
cursor: default;
}
A demo showing how to use <label> tag.
<html>
<body>
<p>
If you click on the italic text that follows or press
<label for="tb"
accesskey="a">Alt+A you will set focus on the text box
</label>
<input id="tb" type="text" value="textbox" size="20"/>
</p><!--from w w w. j a v a2 s . c om-->
</body>
</html>