Why Do Developers Hate The <label> Tag?

One of the most common usability faux pas I find all over the internet is the lack of developers linking up radio buttons with their labels. Why should we be forced to click a tiny little circle when we should be able to click the actual text for that choice?

It's built into the HTML spec so why don't developers use it? Even some of the biggest sites on the web are guilty of this one. I just don't get it.. it's not exactly rocket science.

Just give an ID to your radio button, like so:

 <input type="radio" name="whatever" id="selection1" />

then wrap the text that goes with that radio button in a label tag, as such:

 <label for="selection1">selection 1</label>

Here's a full example with a few selections to choose from.. notice how you can just click the text to select the choice you'd like:




The full code for that was:

 <input type="radio" name="whatever" id="selection1" /> <label for="selection1">selection 1</label><br />
 <input type="radio" name="whatever" id="selection2" /> <label for="selection2">selection 2</label><br />
 <input type="radio" name="whatever" id="selection3" /> <label for="selection3">selection 3</label><br />

With all of the attention being given to usability in this Web 2.0 world, let's make sure we've got 1.0 covered first.

TweetBacks
Comments
Phillip Senn's Gravatar You da man.
# Posted By Phillip Senn | 12/13/06 6:01 PM
TJ Downes's Gravatar maybe we didnt know about it ;) Thanks for the post, this rocks
# Posted By TJ Downes | 12/13/06 6:24 PM
Rey Bango's Gravatar Excellent post Joe.
# Posted By Rey Bango | 12/13/06 7:20 PM
Andrew Calvo's Gravatar Thanks Joe! I've always wanted to make the text selectable, but I never knew how to do it! Hmm.. My ColdFusion teacher should have filled me in on that one......
# Posted By Andrew Calvo | 12/13/06 7:41 PM
Jim's Gravatar Great post. We get so caught up in frameworks and OO we forget the basics of HTML.

The 'legend' and 'fieldset' are two more good form attributes I use quite a bit.

More good stuff at the W3C site:
http://www.w3.org/TR/html4/interact/forms.html

Jim
# Posted By Jim | 12/13/06 8:40 PM
Scott Stroz's Gravatar This functionality also works for check boxes. However, you should use the <label> tag for all your form fields.
# Posted By Scott Stroz | 12/13/06 8:43 PM
Andy Matthews's Gravatar Been using the label tag for a few years now. It really makes your forms feel more responsive.
# Posted By Andy Matthews | 12/14/06 9:23 AM
dan's Gravatar I agree with Scott, I use it for all of my form fields.
# Posted By dan | 12/14/06 11:29 AM
Jeff Coughlin's Gravatar While you're at it go one step further and remove the meaningless break tags (and use CSS to clear to the next line).
# Posted By Jeff Coughlin | 12/14/06 12:00 PM
Joe Danziger's Gravatar Thanks everyone, glad you enjoyed the post! I wrote it in a moment of high frustration.

Scott is correct that you should really be using the &lt;label&gt; tag on all of your form fields. If you're not, I suspect your using tables for layout. You should really be using CSS combined with the correct HTML to lay things out in an accessible way that is Section 508 compliant and able to be handled by screen readers - though much of the web nowadays is no longer compliant with so many image-based captchas all over the place. You can find some good CSS form samples listed here: http://www.smashingmagazine.com/2006/11/11/css-bas...

Jeff: As far as I know the &lt;br /&gt; tag is still perfectly valid for breaking lines. There is some CSS that can be applied to clear floats, but other than that maybe you meant using a DIV which can be overkill in many situations. Let me know if I'm missing something!
# Posted By Joe Danziger | 12/14/06 12:36 PM