HTML for Attribute

HTML for Attribute: This attribute can be used with <label> and <output> elements. When it is used with <label> element it specifies which form element a label is bound to.

HTML for Attribute

It is used with <output> element it defines the relationship between the result of the calculation and the elements used in the calculation.

Syntax: <label for=”element_id”>

Browser Support

This attribute is supported by the following browsers:

  • Chrome
  • Safari
  • Firefox
  • Opera
  • Internet Explorer

 Example 1: for <label> element

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
  <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>
</body>
</html>

Output:

HTML for attribute

Example 2:  for <output> element

<!DOCTYPE html>
<html>
<body>
<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>
</body>
</html>

Output:

HTML for attribute output element