HTML <label> for attribute
Definition and usage
for
The attribute specifies which form element the label is bound to.
Implicit and explicit associations
The label is usually associated with form controls in one of the following two ways: the form control is the content of the label tag, which is an implicit form, or the <label> tag under for
The attribute names a target form id, which is an explicit form.
For example, in XHTML:
Explicit association:
<label for="SSN">ID Number:</label> <input type="text" name="IdNum" id="IN" />
Implicit association:
<label>Birthdate:<input type="text" name="DofB" /></label>
The first label explicitly links the text "Social Security Number:" and the text input control ("SocSecNum") of the form's social security number, its for
The value of the attribute is the same as the id of the control, both are SSN. The second label ("Date of Birth:") is not needed for
The attribute, as well as the related controls, do not need the id attribute. They are implicitly connected by placing the <input> tag inside the <label> tag.
Example
Three radio buttons with labels:
<form action="/action_page.php"> <input type="radio" id="html" name="fav_language" value="HTML"> <label for="html">HTML</label><br> <input type="radio" id="css" name="fav_language" value="CSS"> <label for="css">CSS</label><br> <input type="radio" id="javascript" name="fav_language" value="JavaScript"> <label for="javascript">JavaScript</label><br><br> <input type="submit" value="Submit"> </form>
Syntax
<label for="element_id">
Attribute Value
Value | Description |
---|---|
element_id | The id of the element bound to the tag. |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |