Wednesday, January 14, 2015

What does the for= attribute of labels do?

Sweet jesus, this is probably the most overlooked/misunderstood features of forms even today, and it's basic HTML 4 or possibly earlier.

It binds the label to it form element, most importantly: IT FOCUSES THE ELEMENT WHEN YOU CLICK THE LABEL.

<label for="foo">Foo:</label>
<input id="foo" type="text">

or

<input id="foo" type="checkbox">
<label for="foo">Foo:</label>

IMO, you cannot call yourself a competent web developer if you fail to understand and implement this consistently. You'd be amazed at how many hugely trafficked sites fail to do this.

http://www.reddit.com/r/css/comments/2f54vo/what_does_the_for_attribute_of_labels_do/

No comments: