Monday, July 21, 2008

The <label> tag

A form control usually has a text label that describes it. Using the label tag, you can define the relationship between a text-label and the form control. Labels make a form more accessible. They also give more "hooks" to apply CSS.
This is an example of a form control without a label:
<input type="checkbox" name="spice" value="salt" />Hot
Here is the same form control with a label.
<input type="checkbox" name="spice" value="salt" id="hot" /><label for="hot">Hot</label>
Another way to use the label tag is:
<label><input type="checkbox" name="spice" value="salt" />Hot</label>
Note that for the first method, you need to include the id attribute.

No comments: