Why use 'for' attribute for labels?

In the lessons we are told that it is best practice to use the ‘for’ attribute in a label, but doesn’t the nesting already associate the input to the label? What is the difference between using it and omitting it?

I did find that by doing so the user can click the label and that is the same as clicking the input. Is that it or is there more?


To add to the selected solution, because it doesn’t directly answer:
Looks like there is no difference between nested and explicitly stated since if nested the ‘for’ attribute is by default the content.

Labels don’t actually have to contain the element they’re a label for, in which case they need the id of the element they’re attached to as their for attribute.

For example:
<label for="foo">Foo</label>...some other stuff...<input id="foo">

Thank you, that helps. If it was nested, would the use of the ‘for’ attribute be redundant?

According to specs you can either nest (implicit association) or use for (explicit association):

1 Like

I believe that it also helps with screen readers and accessiblity tools.

1 Like

A great resource, thanks. I’m literally a day old into my learning career. This is great.

Thank you for that. An important consideration.