HTML5 Reference

HTML <label> tag

Definition

The <label> tag is used to define a label for <input>, <meter>, <progress>, <select> and <textarea> tags.

Example


<p>Please fill in our Pie Survey:</p>
<form action="../../htmlintermediate/simpleform.html" id="pieform" method="get">
  <p>Name:<input type="text" name="name"></p>
  <p>Which pie do you prefer?:</p>
  <input type="radio" name="pie" checked="checked" value="Chicken" id="chicken">
  <label for="chicken">Chicken</label>
  <input type="radio" name="pie" value="Fish" id="fish">
  <label for="fish">Fish</label>
  <input type="radio" name="pie" value="Shepherds" id="shepherds">
  <label for="shepherds">Shepherds</label>
  <p>Other stuff you wanna tell us about pies:</p>
  <p><textarea rows="3" cols="30" name="comments"></textarea></p>
  <input type="submit" value="Submit">
</form>

Please fill in our Pie Survey:

Name:

Which pie do you prefer?:

Other stuff you wanna tell us about pies:

Attributes

The following attributes can be used with the <label> tag.


<label> Specific Attributes
Attribute Value Description Example
forattributeSpecifies the control element a label is bound to.

The for attribute must match the id attribute of a control element to bind them together

<input type="radio" name="pie" value="Chicken" 
       id="chicken">
<label for="chicken">Chicken</label>
<label> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<label class="name">Label text</label>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<label id="name">Label text</label>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<label style="color:red;">Label text</label>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<label title="Content info">Label text</label>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<label accesskey="a">Label text</label>
tabindexSpecifies a tab order for the element.

<label tabindex="1">Label text</label>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<label dir="ltr">Label text</label>
<!-- The text will flow from right to left -->
<label dir="rtl">Label text</label>
langSpecifies a language code for the content of the element.

<label lang="en">Label text</label>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<label spellcheck="true">Label text</label> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<label translate="no">Label text</label> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<label contenteditable="true">Label text</label> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<label draggable="true">Label text</label>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<label hidden>Label text</label> 
<label hidden="hidden">Label text</label> 
<label> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<label oncopy="go()">Label text</label> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<label oncut="go()">Label text</label>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<label onpaste="go()">Label text</label>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<label ondrag="go()">Label text</label>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<label ondragend="go()">Label text</label>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<label ondragenter="go()">Label text</label>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<label ondragleave="go()">Label text</label>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<label ondragover="go()">Label text</label>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<label ondragstart="go()">Label text</label>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<label ondrop="go()">Label text</label>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<label onblur="go()">Label text</label>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<label onchange="go()">Label text</label>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<label oncontextmenu="go()">Label text</label>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<label onfocus="go()">Label text</label>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<label oninput="go()">Label text</label>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<label oninvalid="go()">Label text</label>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<label onreset="go()">Label text</label>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<label onselect="go()">Label text</label>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<label onsubmit="go()">Label text</label>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<label onkeydown="go()">Label text</label>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<label onkeypress="go()">Label text</label>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<label onkeyup="go()">Label text</label>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<label onabort="go()">Label text</label>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<label oncanplay="go()">Label text</label>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<label oncanplaythrough="go()">Label text</label>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<label oncuechange="go()">Label text</label>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<label ondurationchange="go()">Label text</label>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<label onemptied="go()">Label text</label>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<label onended="go()">Label text</label>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<label onloadeddata="go()">Label text</label>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<label onloadedmetadata="go()">Label text</label>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<label onloadstart="go()">Label text</label>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<label onpause="go()">Label text</label>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<label onplay="go()">Label text</label>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<label onplaying="go()">Label text</label>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<label onprogress="go()">Label text</label>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<label onratechange="go()">Label text</label>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<label onseeked="go()">Label text</label>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<label onseeking="go()">Label text</label>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<label onstalled="go()">Label text</label>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<label onsuspend="go()">Label text</label>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<label ontimeupdate="go()">Label text</label>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<label onvolumechange="go()">Label text</label>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<label onwaiting="go()">Label text</label>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<label onclick="go()">Label text</label>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<label ondblclick="go()">Label text</label>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<label onmousedown="go()">Label text</label>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<label onmousemove="go()">Label text</label>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<label onmouseout="go()">Label text</label>>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<label onmouseover="go()">Label text</label>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<label onmouseup="go()">Label text</label>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<label onwheel="go()">Label text</label>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<label onscroll="go()">Label text</label> 
Window - NONE