3 ms·
After looking at the source for this, I have a tangential question (feel free to answer even if you aren't the OP): Whats the advantage of creating a separate
by lelanthran 2y ago
After looking at the source for this, I have a tangential question (feel free to answer even if you aren't the OP):
Whats the advantage of creating a separate `label` element before/after the input and using `for=` compared to simply wrapping the target input in the label element, like the code snippet below?
<label>
Your Name?
<input />
</label>
It seems to me that there is a lot less room for error when not using IDs, so I always wrap the input. My pages use a client-side webcomponent to inject fragments of HTML into the page (navbar, footer, etc), and using IDs almost always cause conflicts in the end, so I avoid ID attributes in all but a few very rare instances.
- assimpleaspossi 2y agoNote that the <input> tag does not need and does not use a closing slash and never has in any HTML standard: https://html.spec.whatwg.org/dev/input.html#the-input-element https://html.spec.whatwg.org/dev/input.html#the-input-elemen...
- hk1337 2y agoIt was required in the XHTML 1.0 specs, people carried it over I don’t know why but everyone stopped validating html so nobody cared.
- lelanthran 2y agoSure, but ... what about the question I posed?
- kevindamm 2y agoUpside (of implicit labels) is that there's no more gap and you can avoid the exclusivity of `id` attributes (as you mention). Downside is that screen readers may not handle the implicit label as well as one with explicit for= on it. https://www.w3.org/WAI/tutorials/forms/labels/ https://www.w3.org/WAI/tutorials/forms/labels/