TAG:  label

<label> ... </label>
Available in versions: 4.0
Browser compatibility: Explorer 4, 5  Netscape 6
 
The <label> tag is used to associate text labels with a specific element (control) inside a form (such as an input element). This is done by having the values of the for attribute of the label tag and the id attribute of the form element be the same. Note that you can attach more than one label to the same element. The browser is supposed to render the labels in a special manner to accentuate their appearance.
 
This tag is one of three tags implemented in 4.0 that help set the appearance of a form. The other two are fieldset and legend.
 
However, these three tags are poorly implemented by most browsers.
 
A label element should not contain other label tags. The closing tag is mandatory.
 
Core Attributes
 
class    dir    id    lang    onclick    ondblclick    onkeydown    onkeypress    onkeyup    onmousedown    onmousemove    onmouseout    onmouseover    onmouseup    style    title
 
Attributes
 
accesskey
The accesskey attribute allows you to designate a key on the keyboard that when pressed, along with the alt or meta key, will bring focus to the form element associated with the label. This attribute is poorly supported.
 
for
The for attribute is used to relate the label tag to a specific form control. It must have the exact same value as the id attribute of the form control. However, if the form control is placed inline between opening and closing label tags, the for and id attributes are not needed since the form control and the label are implicitly joined.
 
onblur
The onblur attribute is an event that allows a JavaScript code to execute when an element loses focus (for example, the mouse was clicked onto another element or a tab navigation directed the cursor elsewhere).
 
onfocus
The onfocus attribute is an event that allows a JavaScript code to execute when an element comes into focus (for example, the mouse was clicked onto the element or a tab navigation brought the cursor to the element).
 
Code:
<form>
<fieldset>
<legend>Please Enter Your Name</legend>
<label for="firstname">First Name</label><input type="text" id="firstname">
<br>
<label for="lastname">Last Name</label><input type="text" id="lastname">
</fieldset>
</form>

 
Output:
Please Enter Your Name


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information