WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: questions about fieldset & legend

for

From: Jared Smith
Date: Sep 5, 2006 9:00AM


Lori Brown wrote:
> 1) I get a validation error for putting an <h3> heading inside of a fieldset.
> (on validator.w3.org). It's the 'you can't put that element here' error. Can
> anyone please explain this?

It looks like this is the result of not having a legend. See below.

> 2) On the same small form, I have a fieldset but no legend, as I regarded such
> text as unnecessary -- all the fields have labels, it's a tiny form, etc. But
> the validator is telling me I am missing the opening tag for the legend, and
> asking for it, even though there are no legend tags at all on the page. Again,
> can anyone explain this?

legend is required within fieldset in HTML, but not in XHTML. I'm not sure
the reasons for this difference. If you're getting a failure, I assume you
are using HTML. I did some tests and the validator seems to validate these
correctly across versions.

The legend element cannot contain block level elements, so your <h3> would
need to go either before the fieldset or after the legend. Unfortunately
you cannot assign headings as legends, though this would certainly be
useful as the legends often designate document structure.

fieldset and legend have always been difficult elements to work with and
they will remain this way until HTML allows better styling for them and
the browsers decide to support them in a more consistent manner. If you're
using HTML, be sure to close the element (for instance, with </p>)
immediately before the opening <fieldset> or things will work oddly across
browsers.

> 3) I have long assumed that hidden form fields do not need any labels or
> accessibility accoutrements. Is this true?

Yes, that's correct.

Jared Smith
WebAIM.org