views:

66

answers:

2
  • 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" />
+7  A: 

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
so whatever we write inside `for="..."` and `id="..."` doesn't matter for screen reader software and user, am I right?
metal-gear-solid
Correct - as long as the FOR matches the ID, then the screenreader knows that's the label.. whether that be "B" or "Bazinga" ;)
Dan Heberden
should we consider first method as a best practice?
metal-gear-solid
Descriptive IDs, variables, classnames, all of it - is best practice. Who wants to edit a site full of id="b" class="y" onclick="c(this)" ? heh heh
Dan Heberden
@Dan: It could be the output of some HTML compressor though.
KennyTM
@Kenny correct, I had already mentioned that in my answer :)
Dan Heberden
A: 

I use this:

<label>
    <input>
</label>
reisio
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 G
@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
@reisio- if we keep `input` inside `label` then is `for="..."` needed in this condition
metal-gear-solid
@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 G
@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