HTML <label> for Attribute

❮ HTML <label> tag

Example

<form action="action.php">
  <input type="radio" id="html" name="language" value="HTML">
  <label for="html">HTML</label>

  <input type="radio" id="css" name="language" value="CSS">
  <label for="css">CSS</label>

  <input type="radio" id="javascript" name="language" value="JavaScript">
  <label for="javascript">JavaScript</label>

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

Meaning

The for attribute specifies the id for the form control element the label references.

This is optional when the label encloses the form control it is bound to.

In many cases, particularly when a table is used to structure the form, a <label> tag will not be able to enclose the associated form control, so the for attribute should be used.

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


Standard Syntax

<label for="elementId">...</label>



Browser Support




Status







Attribute Values

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