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.

When 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="/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>
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

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.