HTML for attribute

for attribute associates the input control with the label element. It makes a relationship between the output of calculation and the numbers that involve in the calculation.

Example

<form action="files/for.php" method="post"> 
  <label for="fn">Name: </label><input id="fn"><br>
  <label for="age">Age: </label><input min=0 id="age"><br>
  <label for="pc">Postal code: </label><input id="pc">
  <input type="submit" name="submit">
</form>
Try </>

In the above example, the value of 'for' attribute is the id of the label element.

for attribute values

The value of for attribute is plain text.

Related Tags

The tags which support this attribute are as follows.

<label> tag

label tag defines a caption for the input control as in the above example.

The caption is associated with input field using the for attribute in the label element

<output> tag

output element represents the calculated value of the numbers in input fields.

In case of the output element, the value of 'for' attribute is unique space separated tokens. These tokens include the values of name attributes of the input elements.

Example

<form oninput="div.value = x.valueAsNumber + y.valueAsNumber">
  <input name=p type=number >+
  <input name=q type=number > =
  <output name=div for="p q"></output>
 </form>

Try</>

In the above example the for attribute contains the values of name attributes of input elements that are separated by space.



Was this article helpful?

 

Email:

Message:

Get the newsletter