Latest web development tutorials
 

HTML for Attribute


Definition and Usage

When used together with the <label> element, the for attribute specifies which form element a label is bound to.

Ehen used together with the <output> element, the for attribute specifies the relationship between the result of the calculation, and the elements used in the calculation.


Applies to

The for attribute can be used on the following elements:

Elements Attribute
<label> for
<output> for

Examples

For Example

Three radio buttons with labels:

<form action="demo_form.asp">
  <label for="male">Male</label>
  <input type="radio" name="gender" id="male" value="male"><br>
  <label for="female">Female</label>
  <input type="radio" name="gender" id="female" value="female"><br>
  <label for="other">Other</label>
  <input type="radio" name="gender" id="other" value="other"><br><br>
  <input type="submit" value="Submit">
</form>
Try it Yourself »

Output Example

Perform a calculation and show the result in an <output> element:

<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
  <input type="range" id="a" value="50">100
  +<input type="number" id="b" value="50">
  =<output name="x" for="a b"></output>
</form>
Try it Yourself »

Browser Support

The for attribute has the following browser support for each element:

Element
label Yes Yes Yes Yes Yes
output 10.0 Not supported 4.0 5.1  11.0