DEV Community

Discussion on: Do you still use IDs for unique elements?

Collapse
yoursunny profile image
Junxiao Shi

You can't avoid id in this case:

<label for="f_name">name</label>
<input id="f_name">
Enter fullscreen mode Exit fullscreen mode

(yes I know that id isn't needed if input is inside label, but this may not be feasible if there are other elements in between)

Collapse
patarapolw profile image
Pacharapol Withayasakpunt
Collapse
alohci profile image
Nicholas Stimpson

No, the for attribute cross-references only to the id attribute. This is most important for radio buttons and check-boxes where multiple input elements share a common name to belong to the same group but each needs to be labelled differently.