WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: Using <legend> and <fieldset> on a single drop-down.

for

From: Patrick H. Lauke
Date: May 28, 2021 5:16AM


On 28/05/2021 10:43, Ksenia Blake wrote:

> I just need a bit of advice if I may. Currently we are testing a form, where
> a <legend> tag was used on a Language drop-down without a <fieldset>. In
> most websites, that I have looked, the tags, that are used to group
> elements, are mainly related to radio buttons and checkboxes, to combine
> related items. The question is, is there a specific rules of what items
> should be grouped and what shouldn't.

Per HTML spec, <legend> is only allowed as first child of a <fieldset>,
so a "naked" <legend> is invalid. In practice, nothing bad will
happen...but also, the <legend> will have no actual effect / won't be
announced by assistive technologies as anything other than some piece of
static text.

As for which items should be grouped...any time you think "these various
controls/inputs/buttons are logically grouped and come under some
overarching label/legend" is when you want to do it. Generally, radio
buttons and checkboxes are the ones almost always should be grouped and
given an explicit legend, as they don't make much sense in isolation
(you can have a "Yes" and "No" set of radio buttons, but without
grouping them and giving the group a legend, screen reader users that
land on either one of those radio buttons won't know what they actually
mean/refer to ... this is where a <fieldset> and <legend> are needed to
group them and to provide the actual question/context for those to make
sense).

P
--
Patrick H. Lauke

https://www.splintered.co.uk/ | https://github.com/patrickhlauke
https://flickr.com/photos/redux/ | https://www.deviantart.com/redux
twitter: @patrick_h_lauke | skype: patrick_h_lauke