Advertisement
Home Open Editor ❯

HTML for Attribute

Example

<form action="action.php">
  <input type="radio" id="html" name="language" value="HTML">
  <label for="html">HTML</label><br>
  <input type="radio" id="css" name="language" value="CSS">
  <label for="css">CSS</label><br>
  <input type="radio" id="javascript" name="language" value="JavaScript">
  <label for="javascript">JavaScript</label><br><br>
  <input type="submit" value="Submit">
</form>

Try this code ❯

Meaning

The for attribute specifies the id for the form control element the label references and it should be set to the id value(s) of the elements that target <output> element.

The for attribute allows more than one label to be associated with the same control by creating multiple references.


Standard Syntax

<element for="elementId">


Applies to:

The for attribute can be used on the following element:

Element Attribute
<label> for
<output> for

Advertisement

Attribute Values

Value Description
elementId The id of the element associated with <label> element

More Examples

Example

<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
  <input type="range" id="b" name="b" value="50" /> +
  <input type="number" id="a" name="a" value="10" /> =
  <output name="result" for="a b">50</output>
</form>

Try this code ❯

Home Open Editor ❯
Advertisement