views:

369

answers:

5

A large number of (dare I say most?) sites do not make the labels clickable for their checkbox and radio inputs. It seems to be a huge usability gain for very little effort. Are there any compatibility/functionality/usability issues with using <label> that would discourage developers from using this tag?

Edit: Even StackOverflow seems guilty of this, e.g., when asking a question, the Notify daily of any new answers checkbox label is not clickable.

A: 

I can't see any issues with this. It's a simple JavaScript addition, it will degrade gracefully. The label's content is not touched, so no screen reader or SEO issues. I'd say go ahead, the main reason why people don't do this is probably because it's not difficult, but still a pain in the arse to implement.

Pekka
No, it is plain HTML. No JavaScript involved. It isn't difficult either.
David Dorward
Plain HTML? How? Can you show me? Seriously, I can't think of a non-JS way right now.
Pekka
<input type="checkbox" id="foo"/><label for="foo">Click here!</label>
scunliffe
@scunliffe And that makes the label click sensitive so that it changes the checkbox? Wow, didn't know that.
Pekka
@Pekka - you can also do this on **any** form input, and it will set focus to the input.
RedFilter
+6  A: 

No reason other than laziness. <labels>s are essential for accessibility, and are also pretty handy for those of us who have poor aim with our mouse clicks :)

Ray
Heh, tell that to Jeff Atwood, see my edit above.
RedFilter
oops - though the checkboxes on the profile preferences page do have labels
Ray
Yeah, it is inconsistent throughout the site.
RedFilter
+1  A: 

<label> is a pure HTML tag, no JavaScript is required. I suppose that all (major) browser support this tag, since it is very easy to implement.

A lot of developers are not using it because:

  • it requires more effort (adding all the tags everywhere)
  • they do not know about it existence
  • they do not think it is convenient?!

But there is no reason not to use the tag. Unless you are very limited with your bandwidth, maybe?

Veger
I think the bandwidth comment would only apply to a handful of the most popular sites, e.g. Google.
alex
I totally agree, but this was the only reason I could think of why one would not use the `<label>` tag.
Veger
@alex: it's true, Google does not use the `<label>` tag, I just went into my account settings and checked. I find that really odd.
RedFilter
@OrbMan Google uses `<font>` tags, and it's by design (according to Matt Cutt's blog). Being Google, they need to save precious bytes.
alex
+2  A: 

No, there are no issues with that, but unfortunately this is one of the most ignored html tags. Agreed, this tag is extremely important for accessibility reasons and what is more when it comes to layouts for small devices such as mobiles, you can't live without this.

Sarfraz
+1 for mobile importance. And nice link, thanks. If you go to their signup page, you'll notice they did not use `<label>` tags. :)
RedFilter
@OrbMan: that's why i put up +1 for great question you have asked and guess what even though i have answered it, i myself never cared about it. :)
Sarfraz
+1  A: 

The only difficulty I can think of is that your form controls need to have an ID attribute, and ID attributes need to be unique within your page.

If you were generating form fields programmatically, you would have to generate a unique ID for each of them within each page they appeared on. This could conceivably be an issue.

But generally, yeah, I think it’s just that programmers don’t have it in their heads.

In ASP.NET WebForms (or whatever it’d called), you want the AssociatedControlID attribute on the <asp:Label> element.

Paul D. Waite
+1 for exploration of the barriers to implementation
RedFilter
Form controls don't need an ID:<label><input type="checkbox" ...>Here's a label<label>
Bennett McElwee
I think I have seen browsers that won’t implement the click-label-to-select-form-field without the `id` attribute. And occasionally, for layout reasons, you don’t want your form field inside your `<label>` tag. (Not often though.)
Paul D. Waite