The for attribute on a <label> tag binds (associates) the label to an input element.
Clicking the label places focus on the associated input element.
A for attribute on each of the <label> elements.
Clicking the label will check the associated radio button.
<form action="/tutorial/action.html">
<fieldset>
<legend>Payment Method</legend>
<label for="credit">
<input type="radio" name="card" id="credit" value="credit" checked> Credit Card
</label><br />
<label for="debit">
<input type="radio" name="card" id="debit" value="debit"> Debit Card
</label><br />
<input type="submit" value="Submit">
</fieldset>
</form>
The for attribute on a label binds the label to an input element.
The value of the for attribute is the id of the input element.
Clicking the label places focus on the input element.
Clicking the label of a radio button or checkbox will also check (select) the element.
<label for="element-id">
Value | Description |
---|---|
element-id | id of the input element that the label is bound to. |
Here is when for support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <label>