Formally Labeling Form Parts
As you’ve seen, the explanatory information next to a form element is generally just plain text. For example, you might type “First name” before the text field where the visitor should type her name. (X)HTML provides a method for marking up labels so that you can formally link them to the associated element and use them for scripting or other purposes.
To formally label form parts:
1. | Type <label.
|
2. | If desired, type for="idname">, where idname is the value of the id attribute in the corresponding form element.
|
3. | Type the contents of the label.
|
4. | Type </label>.
Figure 17.20. Marking field labels in a formal way gives you an easy way to identify them in a CSS style sheet.
|
✓ Tips
If you use the for attribute, ...
Get HTML, XHTML, & CSS, Sixth Edition: Visual QuickStart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.