I’ve noticed that a HTML label tag doesn’t need the ‘for’ attribute when you put your input element into the label element:
<label><input type="text">Last name</label>
But I was wondering what’s the best practise. Can anybody help me with that?
Thanks!
It’s used for accessibility for screen readers and the like i.e.
use_the_label_element_to_make_your_html_forms_accessible
So you should use it. And here is a link to convince you about the importance of accessibily.
And here is a little story – making your site accessible can benefit all users – i always was amazed at the amount of effort civic authorities went to for wheelchair accessibilty until I had a daughter and use a push chair. I think websites follow the same rule – everyone benefits.
Apologies for the polemic