Add Labels to a Form with label element

Description

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

Example

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


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="fave">Fruit: <input id="fave" name="fave" /></label>
    </p><!--   w ww. j av  a2 s. co  m-->
    <p>
      <label for="name">Name: <input id="name" name="name" /></label>
    </p>
    <button>Submit Vote</button>
  </form>
</body>
</html>

Click to view the demo

Note

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 assistive technologies.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed