Copyright © tutorialspoint.com

HTML <label> tag



Advertisements

Function:

The HTML <label> tag is used to adda label to a form control like text, textarea etc.

Difference between HTML and XHTML:

NONE

Example:

<p>Which drink would you like ?</p>
<form>
<input type="radio" name="drink" id="pepsi" />
<label for="pepsi">pepsi</label>
<br />
<input type="radio" name="drink" id="cola" />
<label for="cola">cola</label>
</form>

This will produce following result:

Which drink would you like ?


Online Practice:

To Become more comfortable - Do Online Practice

Attributes:

AttributeValueDescription
forcontrol idSpecifies the input control that this label is for. This value must be the same as the value in the input control's "id" attribute.

Standard Attributes:

AttributeDescription
classDocument wide identifier
dirSpecifies the direction of the text
idDocument wide identifier
titleSpecifies a title to associate with the element.
styleHelps to include inline casecadubf style sheet.
langSets the language code.
xml:langSets the language code.

Event Attributes:

AttributeDescription
accesskeyAccess keys (or shortcut keys)
onfocusScript runs when control gets focus
onblurScript runs when control loses focus
onclickScript runs when a mouse click
ondblclickScript runs when a mouse double-click
onmousedownScript runs when mouse button is pressed
onmouseupScript runs when mouse button is released
onmouseoverScript runs when mouse pointer moves over an element
onmousemoveScript runs when mouse pointer moves
onmouseoutScript runs when mouse pointer moves out of an element
onkeypressScript runs when key is pressed and released
onkeydownScript runs when key is pressed
onkeyupScript runs when key is released

Copyright © tutorialspoint.com