Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Form Labels

Rated 4.18 (Ratings: 20) (Add your rating)

Log in to add a comment
(5 comments so far)

Want more?

 
Picture of keihin

Ron Thigpen

Member info | Full bio

User since: March 05, 2001

Last login: March 05, 2001

Articles written: 1

Form element labels aid usability by allowing users to click label text to select radio and checkbox elements. They are implemented using the <label for="elementID"> tag, in conjuction with the ID attribute of the <input> tag. Adding a style selector for labels lets you change the cursor (and other style accessible presentation characteristics) to indicate the clickable labels. This works in IE5+, and Moz0.9+. Older, non-compliant browsers will simply ignore the tag, making it fully backwards compatible.

Example

Input 1 Label
Input 2 Label
Input 3 Label

Input 4 Label
Input 5 Label
Input 6 Label

Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Form Label Example</title>
<style>
label {cursor: hand;}
</style>
</head>
<body>
<form action="formlabel.htm" method="post" name="theform" id="theform">
<label for="input1">Input 1 Label</label>
<input type="radio" name="input" id="input1"><br>
<label for="input2">Input 2 Label</label>
<input type="radio" name="input" id="input2"><br>
<label for="input3">Input 3 Label</label>
<input type="radio" name="input" id="input3"><br>
<br>
<label for="input4">Input 4 Label</label>
<input type="checkbox" name="check1" id="input4"><br>
<label for="input5">Input 5 Label</label>
<input type="checkbox" name="check2" id="input5"><br>
<label for="input6">Input 6 Label</label>
<input type="checkbox" name="check3" id="input6"><br>
</form>
</body>
</html>

W3 Reference

W3 HTML 4.01 reference -- label element

Cool!

Submitted by djc on September 19, 2001 - 08:36.

Even though I'm not much of a HTML/CSS person, I have to say I've always wondered how websites did that and why more didn't do it because it seems very usefull. Thanks!

login or register to post comments

Older browsers

Submitted by theuiguy on September 19, 2001 - 08:41.

The label tag has actually been supported since IE4, so it surprises me how few people use it. Although the label tag is usually ignored by older browsers, I've observed situations where Netscape 4.x will lose text on the page when it encounters a label tag. This usually happens in nested tables. You can sometimes remove just the first label tag and everything will work again. Don't let this discourage you from using labels, just make sure you test well.

I'd recommend against changing the cursor style for radio button/checkbox labels. This could lead to user confusion since the hand cursor is usually used for links. Users may expect the label to take them to a new page. Also notice that operating systems do not change the cursor style for clickable labels.

You can accomplish something similar for Netscape 4.x using a link and javascript. For example,

&lt;input type="radio" Name="AmPm" value="0"&gt;&lt;a href="javascript:toggleRadio(document.frm.AmPm, 0)" style="text-decoration:none; color:#000000"&gt;AM&lt;/a&gt;

Whether this is worthwhile depends on your target audience. I notice that most of the time I click the text label first, so I strongly recommend adding label tags. They are also required for ADA Section 508 compliance.

login or register to post comments

to web based

Submitted by ericd on March 8, 2002 - 13:03.

More and more desktop apps are being converted to web-based apps and features like this allow designers to maintain application-type interaction within the browser. Very cool.

login or register to post comments

No subject

Submitted by TonyHaddon on March 22, 2002 - 12:37.

Thanks Ron. I've learned something new. I love that. Cheers.

login or register to post comments

blah

Submitted by ericd on March 22, 2002 - 13:11.

Ron, Just a minor comment... I would suggest that the text label follow the checkbox or radio button rather than the other way around... since you are providing code and all.

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.