HTML <label>
Tag
Topic: HTML5 Tags ReferencePrev|Next
Description
The <label>
tag is used to define a caption for a form control in HTML form. Each label element is associated with exactly one form control either by using the for attribute, or by placing the control element inside the label element.
The following table summarizes the usages context and the version history of this tag.
Placement: | Inline |
---|---|
Content: | Inline and text |
Start/End Tag: | Start tag: required, End tag: required |
Version: | HTML 4, 4.01, 5 |
Tip: The <label>
element provides a usability improvement by making the form more accessible for mouse users. It provides a larger clickable area for small items, like checkboxes or radio buttons, so that if the user clicks on the text within the <label>
element, it toggles the control.
Syntax
The basic syntax of the <label>
tag is given with:
The example below shows the <label>
tag in action.
Example
Try this code »<form>
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>
</form>
Tag-Specific Attributes
The following table shows the attributes that are specific to the <label>
tag.
Attribute | Value | Description |
---|---|---|
for |
form-control-id | Specifies which form control a label relates to. |
form |
form-id | Specifies the <form> element that the <label> element is associated with (its form owner). |
Global Attributes
Like all other HTML tags, the <label>
tag supports the global attributes in HTML5.
Event Attributes
The <label>
tag also supports the event attributes in HTML5.
Browser Compatibility
The <label>
tag is supported in all major modern browsers.
Basic Support—
|
Further Reading
See tutorial on: HTML Forms.
Other form-related tags: <form>
, <fieldset>
, <legend>
, <input>
, <textarea>
, <select>
, <optgroup>
, <option>
, <button>
.