[thelist] form label tag

James Aylard evolt at pixelwright.com
Thu Sep 12 17:35:00 CDT 2002


Jonathan,

>     <label>One<input type="text" id="1" name="1" /></label>
>
> is perfectly good html.  But
>
>     <label for="1">One</label><br />
>     <input type="text" id="1" name="1" />
>
> is perfectly valid, too -- in fact, that's what the 'for' attr is for --
> when the relevant input *isn't* a child of the label, <label>'s 'for'
says,
> well, what the <label>'s a label for. . .

    But remember that ids must _not_ begin with a digit. Sure, IE will let
you do it (at least pre-IE 6 standards-compliance mode [1]), but it's
contrary to the HTML 4.x recommendation, and other browsers likely will not
support it. [2]
    Also, with regard to nesting form elements within a label element, it
_is_ valid, as you and others have said, but nesting is intended to create
an implicit relationship between the label element and its associated form
element, rather than using the label element's "for" attribute, which
creates an explicit association between the label element and the form
element (and is much more flexible) [3]. The WCAG guidelines mixed the two
approaches -- confusing them, IMO -- by both nesting and using the "for"
attribute.

1.
http://msdn.microsoft.com/library/en-us/dnie60/html/cssenhancements.asp#csse
nhancements_topic7
2. http://www.w3.org/TR/html4/types.html#type-idref
3. http://www.w3.org/TR/html4/interact/forms.html#edef-LABEL

James Aylard




More information about the thelist mailing list