From http://www.w3schools.com (Copyright Refsnes Data)

HTML <label> tag


Example

An simple HTML form with two input fields and related labels :

<form>
  <label for="male">Male</label>
  <input type="radio" name="sex" id="male" />
  <br />
  <label for="female">Female</label>
  <input type="radio" name="sex" id="female" />
</form>

Try it yourself!


Definition and Usage

The <label> tag defines a label for an input element.

The label element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the label element, it toggles the control.

The for attribute of the <label> tag should be equal to the id attribute of the related element to bind them together.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The <label> tag is supported in all major browsers.

Note: Not supported in Safari 2 or earlier versions.


Differences Between HTML and XHTML

NONE


Optional Attributes

DTD indicates in which DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.

Attribute Value Description DTD
for id_of_another_field Defines which form element the label is for.

Note: If this attribute is not specified, the label is associated with its contents.

STF

Standard Attributes

id, class, title, style, dir, lang, xml:lang, accesskey

For a full description, go to Standard Attributes.

Event Attributes

onfocus, onblur, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For a full description, go to Event Attributes.


From http://www.w3schools.com (Copyright Refsnes Data)