Skip to Content
Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP
book

Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP

by Steven M. Schafer
August 2005
Intermediate to advanced
840 pages
17h 29m
English
Wrox
Content preview from Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP

9.18. Field Labels

The label tag (<label>) is used to define text labels for fields. This tag has the following format:

<label for="id_of_related_tag">text_label</label>

For example, the following code defines a label for a text box:

<p><label for="FirstName">First Name: </label>
<input type="text" name="FirstName" id="FirstName" value=""
size="30" maxlength="40"></p>

The label field's for attribute should match the id of the field for which it is intended. The main purpose of the label tag is accessibility—most users will be able to ascertain the purpose of fields in your forms by sight. However, if the user agent does not have a visual component, or if the user is visually impaired, the visual layout of the form cannot be relied on to match labels and fields. Note that if the user agent supports it, the user can also click on the field label to select the appropriate field.

The <label> tag's for attribute ensures that the user agent can adequately match labels with fields for the user, if necessary.

Notice the use of both the id and name attributes in the text input field tag. HTML requires a field to have a name tag for its data to be submitted. However, the label tag requires an id value in its matching input field.

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Advanced PHP for Web Professionals

Advanced PHP for Web Professionals

Christopher Cosentino

Publisher Resources

ISBN: 9780764588204Purchase book