W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2011

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

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Thu, 17 Feb 2011 10:23:33 -0500
Message-ID: <4D5D3D75.1010607@mit.edu>
On 2/17/11 8:37 AM, Matthew Raymond wrote:
> <label>
>    <input type='radio' name='a'>
>    <textarea></textarea>
> </label>
>
>     The label doesn't specify which control is the one it's labeling.

But the spec does:

   If the for attribute is not specified, but the label element has a
   labelable form-associated element descendant, then the first such
   descendant in tree order is the label element's labeled control.

Now the markup here is invalid per the spec (<label>'s content model 
says "no descendant labelable form-associated elements unless it is the 
element's labeled control"), but which control is labeled is quite 
well-defined.

> 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.

We all agree it's crappy markup.

People do this all the time.

-Boris
Received on Thursday, 17 February 2011 07:23:33 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:30 UTC