4 out of 5 rated this helpful - Rate this topic

label element | label object

[This documentation is preliminary and is subject to change.]

Specifies a label for another element on the page.

HTML 4.01 Specification, Section 17.9.1

Standards information

HTML information

Closing Tagrequired
CSS Displayinline

DOM Information

Inheritance Hierarchy

 Node
  Element
   HTMLElement
     label

Remarks

To bind a LABEL to another control, set the FOR attribute of the LABEL element equal to the ID of the control. Binding a LABEL to the NAME attribute of the control has no effect. However, to submit a form, you must specify a NAME on the control to which the LABEL element is being bound.

There are two ways to underline the designated access key. The rich text support in the LABEL element makes it possible to wrap the U element around the character in the label text specified by the ACCESSKEY attribute. If you prefer to use cascading style sheets (CSS) to apply style formatting, enclose the designated character in a SPAN and set the style to "text-decoration: underline".

If the user clicks the LABEL, the onclick event fires on the LABEL and then on the control specified by the htmlFor property. Pressing the access key for the LABEL sets the focus but does not fire the onclick event.

Labels cannot be nested.

Examples

This example uses the LABEL element and the ACCESSKEY attribute to set focus on a text box.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/accesskey.htm


<LABEL FOR="oCtrlID" ACCESSKEY="1">
    #<SPAN style="text-decoration:underline;">1</SPAN>: Press Alt+1 to set focus to textbox
</LABEL>
<INPUT TYPE="text" NAME="TXT1" VALUE="binding sample 1" 
       SIZE="20" TABINDEX="1" ID="oCtrlID">

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Binds to nested A elements (IE7)

Under HTA, a LABEL binds to nested A elements. The following code creates an invisible hyperlink:

<LABEL >Click here! <A HREF="about:blank" ></A ></LABEL >

This bug has been fixed in IE 8 but HTA displays pages in IE 7 compatibility mode unless explicitly instructed otherwise.