Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Upside (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/


Note 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-elemen...


It 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.


Sure, but ... what about the question I posed?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: