HTML Tutorial - HTML Form Label

The label element provides some context for each element in a form. It has local Attributes:for, form .


The following code shows how you can give the user some context.

  <form method="post" action="">
      <label for="fave">Fruit: <input id="fave" name="fave" /></label>
    </p><!-- w w  w  . ja v  a2  s .c om-->
      <label for="name">Name: <input id="name" name="name" /></label>
    <button>Submit Vote</button>

Click to view the demo


An id attribute is added to the input elements and label is using these ids as the value for the for attributes on the label elements. This is how you associate labels with inputs, which makes processing forms simpler for screen readers and other technologies.