-1
  • 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" />
Andrew Jaffe
  • 26,554
  • 4
  • 50
  • 59
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852

2 Answers2

7

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.

Dan Heberden
  • 10,990
  • 3
  • 33
  • 29
-2

I use this:

<label>
    <input>
</label>
reisio
  • 3,242
  • 1
  • 23
  • 17
  • 1
    I believe IE6 isn't supporting implicit labels. It's for the best to do explicit labels until the use of this browsers dies off. – Gert Grenander May 24 '10 at 14:42
  • @Gert G: is it? Do you really think IE6 users will _even notice_ the difference? :p I don't. I'd bet money they wouldn't. (for the record, what IE6 doesn't support is the label functionality which makes an onclick on the label send focus to what it's labelling) – reisio May 24 '10 at 15:14
  • @reisio- if we keep `input` inside `label` then is `for="..."` needed in this condition – Jitendra Vyas May 24 '10 at 15:22
  • @reisio Well, if not for IE... avoid it to have the label work in the screen readers that only support explicit labels or has buggy support for implicit labels. – Gert Grenander May 24 '10 at 18:19
  • @metal: no, the 'for' attribute would not be needed at all @Gert: screen readers are a ridiculous concept. A TTS engine aimed at barely-parsed HTML would be much smarter, and on average cost several hundreds of dollars less. This simple HTML has been standard since at least before 1998 (http://www.w3.org/TR/REC-html40-971218/interact/forms.html#idx-label-1), and all relevant UAs support it. – reisio May 25 '10 at 04:37