[whatwg] Form controls inside a label but not labelled by it

Matthew Raymond mattraymond at earthlink.net
Thu Feb 17 05:37:40 PST 2011

On 2/17/2011 7:10 AM, Mounir Lamouri wrote:
> According to a comment of Hixie in [1], this case has been handled by
> the specs in 2004 but it doesn't seem to be any more and UA's have a
> very different behaviour here:
> - Firefox: focus and activate the labelled element ;
> - Webkit: focus the form control and activate the labelled element ;
> - Presto and IE9 RC: focus the form control (doesn't activate the
> labelled element).
> I think Webkit's behaviour makes the more sense here and it would be
> nice to have it specified.

   Let's take a look at a snippet of the markup:

  <input type='radio' name='a'>

   The label doesn't specify which control is the one it's labeling. In
fact, the author is attempting to use it as a double label for two
controls, so semantically it would seem like there is an attempt to
focus both controls simultaneously. Worse, there's no actual content in
the label besides controls and whitespace.

On 2/17/2011 8:15 AM, Anne van Kesteren wrote:
> The spec defines the Opera/IE behavior which I think is actually
> better.
> If you nest elements with activation behavior only the innermost is
> activated. You can also test this by e.g. nesting <a> elements and
> see which link is followed.

   I agree. If you assume that a <label> can label only one control at a
time, then the one above can label either the <input> or the <textarea>,
but not both. The Webkit behavior is functionally convenient, but
semantically it's nonsense, and it could be triggered just by someone
accidently placing the closing tag in the wrong place.

   However, that does leave us in a situation where we have to use
Javascript to achieve the Webkit behavior. Is there a semantic way to do
this at all?

More information about the whatwg mailing list