Should I repeat label text in for=“…” and id=“..”?
-
04-10-2019 - |
Question
- Is there any cons of 2nd method? Why http://www.webstandards.org/ decided to use 2nd method
- Is first method better than first for screen reader users?
First
<label for="name">Name</label>
<input id="name" />
Second
<label for="n">Name</label>
<input id="n" />
Solution
The only 'con' is that the id is non-descriptive. For a page with little content, this wouldn't be a big deal but for a larger page, using a descriptive ID is helpful in development. Too, ID's need to be unique, so the single letter approach would get old at input #26 :p
As a side note, webstandards.org might have run their html through a compression utility that changes their descriptive IDs into single letters to minimize download time. e.g.
Their in-house code is your first example and the compressor spit out your second.
OTHER TIPS
I use this:
<label> <input> </label>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow