Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <label> for Attribute

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.

Example

#

A for attribute on each of the <label> elements.
Clicking the label will check the associated radio button.

Payment Method

<form action="/tutorial/action.html">
  <fieldset>
    <legend>Payment Method</legend>
  
    <label for="credit">
       <input type="radio" name="card" id="credit" value="credit" checked> &nbsp;Credit Card
    </label><br />
    <label for="debit">
      <input type="radio" name="card" id="debit" value="debit"> &nbsp;Debit Card
    </label><br />

    <input type="submit" value="Submit">
  </fieldset>
</form>

Using for

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.


Syntax

<label for="element-id">

Values

#

Value Description
element-id id of the input element that the label is bound to.

Browser support

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

You may also like

 Back to <label>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides