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.
<!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 w w . ja v a2 s .c om-->
<p>
<label for="name">Name: <input id="name" name="name" /></label>
</p>
<button>Submit Vote</button>
</form>
</body>
</html>
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.