Latest

recent

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>


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

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

Event Attributes

onfocus, onblur, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
HTML Label tag Reviewed by 1000sourcecodes on 03:46 Rating: 5
Powered by Blogger.