for Attribute


 

Where to use the for Attribute

  • As Type IDREF:
    for is declared on the element: label

Description

The for attribute may be specified on the label element and should be given the id attribute of the form control for which is it a label. This creates an explicit association between the label and the form control.

This association allows user agents to implement such features as bringing the relevant form control into focus when the user clicks on the its label. This is particularly useful for input type="checkbox" and input type="radio" where, in many user agents, clicking on the label is equivalent to clicking on the radio button or checkbox itself (these controls tend to be rather small so this facility can make them easier to use).

An alternative method of associating a form control with a label is to include the form control within the label's content. This is less flexible than using the for attribute, however.


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 16 May 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Attribute Index (XHTML 1.1) > for Attribute (XHTML 1.1)