Syntax | This element uses separate opening and closing tags.<label>...</label> |
---|---|
Usage | The <label> tag is used to associate labels with form controls. Each label can be associated with exactly one form control. However, more than one label can be associated with a single control. There are two methods available for associating a label with a control. Either the control can be placed between the opening and closing <label> tags, or the label's for attribute can be set to match the control's id attribute. HTML <label> example with the input control placed between the opening and closing <label> tags. <form action="example_input.php" method="post"> <p> <label>Enter Text <input type="text" name="texttest"></label> <br><input type="submit" value="Send"> <input type="reset"> </p> </form> XHTML <label> example with the input control placed between the opening and closing <label> tags. <form action="example_input.php" method="post"> <p> <label>Enter Text <input type="text" name="texttest" /></label> <br /><input type="submit" value="Send" /> <input type="reset" /> </p> </form> HTML <label> example using the label's for attribute matched with the input control's id attribute. <form action="example_input.php" method="post"> <p> <label for="labelexample">Enter Text</label> <input id="labelexample" type="text" name="texttest"> <br><input type="submit" value="Send"> <input type="reset"> </p> </form> XHTML <label> example using the label's for attribute matched with the input control's id attribute. <form action="example_input.php" method="post"> <p> <label for="labelexample">Enter Text</label> <input id="labelexample" type="text" name="texttest" /> <br /><input type="submit" value="Send" /> <input type="reset" /> </p> </form> |
Content Model | The <label> element can contain the following tags, and Text, between its opening and closing tags. <a>
<abbr>
<acronym>
<applet>
<b>
<basefont>
<bdo>
<big>
<br>
<button>
<cite>
<code>
<del>
<dfn>
<em>
<font>
<i>
<iframe>1
<img>
<input>
<ins>
<kbd>
<label>2
<map>
<object>
<q>
<s>
<samp>
<script>
<select>
<small>
<span>
<strike>
<strong>
<sub>
<sup>
<textarea>
<tt>
<u>
<var>
Notes:1. The <label> element can contain the <iframe> tag when using DTD Transitional and Frameset documents but not Strict documents. 2. The <label> element can contain the <label> tag when using XHTML but not HTML. 3. Red tags have been deprecated and are allowed in DTD Transitional and Frameset documents but not Strict documents. |
Required | Tag Specific | Core | Focus | Events | Language |
---|---|---|---|---|---|
for | id class style title | accesskey onblur onfocus | onclick ondblclick onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup | dir lang xml:lang1 | |
Notes: 1. XHTML only. |
Attribute | Description |
---|---|
for | The for attribute is used to associate the label with the control. This is accomplished by setting the value of the for attribute to match the control's id attribute. |
id | The id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example |
class | The class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. See class Example |
style | The style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. See style Example |
title | The title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example |
accesskey | The accesskey specifies a shortcut key for a tag. The action that is taken when an access key is invoked depends on the tag and may also depend on the browser. For example, if it is used with an <a> tag, some browsers may follow the link when the access key is invoked and other browsers may give focus to the link. See accesskey Example |
onblur | The onblur attribute specifies a script to be run when the tag loses focus. See onblur Example |
onfocus | The onfocus attribute specifies a script to be run when the tag receives focus. See onfocus Example |
onclick | The onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. See onclick Example |
ondblclick | The ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. See ondblclick Example |
onkeydown | The onkeydown attribute specifies a script to be run when a key is pressed down. See onkeydown Example |
onkeypress | The onkeypress attribute specifies a script to be run when a key is pressed and released. See onkeypress Example |
onkeyup | The onkeyup attribute specifies a script to be run when a key is released. See onkeyup Example |
onmousedown | The onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. See onmousedown Example |
onmousemove | The onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. See onmousemove Example |
onmouseout | The onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it. See onmouseout Example |
onmouseover | The onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. See onmouseover Example |
onmouseup | The onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object. See onmouseup Example |
dir | The dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example |
lang | The lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example |
xml:lang | The xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example Note: XHTML only. |