Lars Pind

internet software, coaching, and entrepreneurship

Lars Pind - internet software, coaching, and entrepreneurship
Check out Coach TV, my video blog on happiness and personal development for geeks.

Always use the for attribute on labels

June 09, 2006 · 0 comments

In the same vein as the last post: For a while there, I thought I could take a shortcut by saying:

<label><input type="checkbox" name="foo" value="1" /> The label</label>

Instead of the more cumbersome:

<label for="mycheckbox"><input type="checkbox" name="foo" id="mycheckbox" value="1" /> The label</label>

That way I don’t have to worry about setting the ID for the checkbox, making sure it’s unique, and all that.

It works fine in Firefox, and Safari ignores it, just like it ignores any old label tag. But Internet Explorer, of course, had to not work. So forget about that, and just use the for and id attributes like you always did. Bah.