Skip to Content
Web Design in a Nutshell, 3rd Edition
book

Web Design in a Nutshell, 3rd Edition

by Jennifer Robbins
February 2006
Intermediate to advanced
826 pages
63h 42m
English
O'Reilly Media, Inc.
Content preview from Web Design in a Nutshell, 3rd Edition

There are two ways to apply a label to a form control. One is to nest the control and its associated description within the label element. Following is an example of labels being applied to a simple form with this method.

    <form action="/cgi-bin/guestbook.pl" method="GET"><label>Login account: <input type="text" name="login" /></label>
    <label>Password: <input type="password" name="password" /></label>
    <input type="submit" />
    </form>

The other method is to associate the label with an id value specified in the input form. The for attribute says which control the current label is for. This method is useful for form fields that are not juxtaposed with their descriptions, such as when they span across different table cells. The following is an example of the label element referencing an id.

    <form action="/cgi-bin/guestbook.pl" method="GET"><label for="log">Login account:</label>
    <input type="text" name="login" id="log" />

    <label for="pswd">Password:</label>
    <input type="password" name="password" id="pswd" />
    <input type="submit" />
    </form>
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Responsive Web Design with HTML5 and CSS3

Beginning Responsive Web Design with HTML5 and CSS3

Jonathan Fielding

Publisher Resources

ISBN: 0596009879Errata Page