Step by Step

Fieldset and legend: which form fields to group, and why a heading above them isn't enough

8 min read
Mikhail ShaymardanovWeb Quality and Accessibility Expert

On Tab, a screen reader usually skips the <h2> above a group of radio buttons. It announces the focused button and its group's name, taken from the <legend> of a <fieldset>. NVDA, a free screen reader, says that name once, as the focus enters the group, followed by “grouping”, so the question comes before the choices. The <h2> can even move inside the legend and stay a heading.

Naming a group of form fields


#Does a heading above radio buttons replace fieldset and legend?

No. On Tab, a screen reader announces the focused button and the name of the group the keyboard focus enters. A heading above the buttons is neither. WebAIM's guide to forms warns that text placed between form fields is usually skipped.

The <fieldset> element wraps fields that belong together, such as the choices for a single question. Its <legend> gives the group its name, the same way a <label> names a field. Someone filling in the form with the keyboard and a screen reader then hears the question along with the first choice. Without a <legend>, the group has no name. The W3C, which writes web standards, also advises a visual grouping on screen.

In Firefox with NVDA, the free screen reader for Windows, a group of radio buttons behaves in four ways:

  • all the buttons in the group make up a single Tab stop;
  • on the way in, NVDA says the legend, “grouping”, then the button that has focus;
  • moving between buttons with the arrow keys doesn't bring the legend back;
  • without a legend, the fieldset isn't announced.

On the checkout page of Quill Stationery, our demo shop, “Shipping method” is a 22 px <h2> sitting above the three buttons. In Firefox, starting from the “Email address” field, we counted a single Tab stop for all three.

Firefox's accessibility inspector shows the accessibility tree, the version of the page that screen readers receive. There, the heading sits level with the buttons' labels. NVDA announces the containers of the focused field as the focus moves into them, as one of its developers explained in 2011. A heading next to the buttons doesn't contain them. As a result, the listener hears “Pick up at the workshop”, its radio button role and its position among the three, with no “Shipping method”.

Screenshot: Firefox's accessibility inspector on the checkout page. Under the form, an unnamed generic element holds the “Shipping method” heading, then three labels; the first one, expanded, holds the “Pick up at the workshop” radio button.Marker 1. The row of the “Shipping method” heading, at the same level as the labels of the buttons. Marker 2. The three labels and their radio buttons, with no named group above them.
In Firefox's accessibility inspector, the “Shipping method” headingmarker 1 sits next to the three radio buttons and their labelsmarker 2; no named group contains them.

#When should you use fieldset and legend, and which fields don't need them?

A fieldset goes around fields whose labels, read on their own, don't say what they answer: the radio buttons of one question, or blocks of fields with identical labels. In WCAG, the international accessibility guidelines, this grouping falls under the success criterion Info and Relationships: a testable rule at level A, the minimum. Technique H71 shows how to meet it with these two elements. In the EU, EN 301 549 requires every web page to meet that criterion. It's the voluntary standard drafted to support the European Accessibility Act.

The number of fields doesn't matter. The W3C's rule of thumb is that a group of fields inside a larger form gets a fieldset and legend when it needs its own heading to describe it. WebAIM adds that the pair should only be used when the fields need a shared label, so a single checkbox whose label makes sense alone goes without one. A date split into day, month and year is a group, and the British government's GOV.UK Design System puts it in a fieldset.

Screenshot: the “Your order” page of Quill Stationery. On the left, the Email address field, three radio buttons under the Shipping method heading, two four-field address blocks separated by a checkbox, and the Continue to payment button; on the right, the order summary with a photo of a notebook and a bottle of ink, and a Promo code field.Marker 1. The three shipping method radio buttons, under their heading. Marker 2. The Shipping address block, four fields. Marker 3. The Billing address block, with the same four labels. Marker 4. The Billing address same as shipping address checkbox, on its own. Marker 5. The Promo code field, alone in its form.
On the Quill Stationery page, the radio buttonsmarker 1 and the two address blocksmarker 2marker 3 get a fieldset; the checkboxmarker 4 and the promo codemarker 5 keep their label.
To group in a fieldset: three groups on the checkout page
GroupWhat the labels are missingLegend
marker 1 Three radio buttonsThe question being askedShipping method
marker 2 Four address fieldsThe block they belong toShipping address
marker 3 The same four labelsThe block they belong toBilling address
To leave without a fieldset: two fields on their own
FieldWhat's enough
marker 4 “Billing address same as shipping address” checkboxIts label
marker 5 “Promo code” form, a single fieldIts label

For radio buttons, the W3C tutorial says to always group them. The two address blocks repeat “Full name”, “Street address”, “Postal code” and “City”. Without a fieldset, the two “Postal code” fields sound alike. With one fieldset per block, NVDA names the block on the way in, then doesn't repeat it on the fields that follow.

The single checkbox and the one-field form keep their label. No fieldset goes around the whole form either: it would contain the other three, and the W3C advises against nesting fieldsets when there's no need.

Accessible forms in HTML: required fields, error messages and validation

#How do you style fieldset and legend without changing how the form looks?

Put the <h2> inside the <legend>, then strip the <fieldset> of its border and spacing: the heading keeps its look, and the group gets its name. Three CSS rules are enough.

#How do you keep the heading's look inside the legend?

The HTML specification allows a heading inside a legend: the legend names the group, and the heading places it in the outline of the page. In Firefox's inspector, we found the <h2> under the legend, still marked as a heading. A screen reader still lists it among the page's headings.

Screenshot: the “Shipping method” heading of Quill Stationery, with a red dot before it, above three boxed radio buttons: Pick up at the workshop, Home delivery, Parcel locker.Marker 1. The “Shipping method” heading, above the three radio buttons.
The “Shipping method” headingmarker 1 looks the same inside the legend: only the markup changes, and the three buttons get the name of their group.

Avoid

<div class="block">
  <h2>Shipping method</h2>
  <div class="choices">
    <label><input type="radio" name="shipping" value="pickup"> Pick up at the workshop</label>
    <label><input type="radio" name="shipping" value="home"> Home delivery</label>
    <label><input type="radio" name="shipping" value="locker"> Parcel locker</label>
  </div>
</div>

Correct

<fieldset class="block">
  <legend><h2>Shipping method</h2></legend>
  <div class="choices">
    <label><input type="radio" name="shipping" value="pickup"> Pick up at the workshop</label>
    <label><input type="radio" name="shipping" value="home"> Home delivery</label>
    <label><input type="radio" name="shipping" value="locker"> Parcel locker</label>
  </div>
</fieldset>

By default, the browser draws the legend across the top border and gives the fieldset a border, margins and padding. The three rules below come from the base stylesheet of Bootstrap 5.3.9. They remove that frame and float the legend, which lifts it off the border and lays it out like an ordinary block. That's why, by design, a Bootstrap 5 legend no longer sits on the fieldset's border.

fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { float: left; width: 100%; padding: 0; }
legend + * { clear: left; }

The legend can also be hidden from view. Shrunk to 1 px by Bootstrap's .visually-hidden class, it still names the group: we saw this in the accessibility trees of both Firefox and Chrome. A 22 px <h2> above the buttons, by contrast, usually stays silent on Tab.

Hidden with display: none, though, the legend drops out of the accessibility tree, and under the W3C's rules the group then loses its name. Chrome follows those rules. Firefox keeps the name: a gap reported to Mozilla in 2018 that is still open. We reproduced it on our demo, so check in both browsers.

Two patterns meet the Info and Relationships criterion, and we recommend the first:

  1. The <h2> inside the legend: one text, the same look, and a heading that still appears in the list of headings; it takes the three CSS rules.
  2. A visible <h2> and a hidden legend: acceptable but not recommended. A screen reader user hears both texts when reading the page, as the GOV.UK Design System warns, and the two have to be kept identical.
The aria-hidden attribute: when to use it, and what to do when Tab reaches what it hides

#How do you check that the group has a name?

In Firefox's accessibility inspector, select a radio button: it should sit inside a group that carries the text of the legend. On the fixed page, we found “Shipping method” there.

Screenshot: Firefox's accessibility inspector on the fixed page. Under the form, a group element named “Shipping method” holds a label row with the same name, then the three labels of the radio buttons, the first one expanded down to the “Pick up at the workshop” button.Marker 1. The row of the group named “Shipping method”. Marker 2. The three labels and their radio buttons, inside that group.
On the fixed page, the radio buttons and their labelsmarker 2 sit inside a group named “Shipping method”marker 1, the name NVDA says on the way in.

With NVDA and Firefox, start from the “Email address” field and press Tab. NVDA should say the legend, “grouping”, then the button, and on Down arrow nothing more about the group. We expect this from the change log of NV Access, the company that makes NVDA, and from an issue in its code repository. Our guides explain how to install NVDA and run it on a Mac in a virtual machine.

Click the demo, then press the key shown, or move on with “Next step”. Escape leaves the demo.
3 steps

On the fixed Quill Stationery page, NVDA should say the legend “Shipping method” and the word “grouping” when the focus enters the radio buttons, then nothing about the group on the next arrow press.

On the Quill Stationery page, three fieldset elements were enough. The checkbox and the promo code keep their label. In Chrome, our before and after screenshots don't differ by a single pixel, on a wide screen or on a phone. Firefox's inspector counts three named groups. On Tab, the <h2> that the screen reader used to skip above the radio buttons has become the name of their group.


Page by page, the Includdy scan and its manual guides for forms find radio button and checkbox groups that have no name. For each one, Includdy's guided fix shows the faulty HTML beside a fixed version with a legend. Its AI suggests the fix, and you review it before it goes into your code.


Share this article

Frequently asked questions

It depends on the screen reader and how it's set up. The W3C forms tutorial explains that some screen readers, depending on their configuration, read the legend with every field, only once, or, rarely, not at all. NVDA says it once, when the focus enters the group. VoiceOver, Apple's screen reader, reads it twice on the first field in Safari, according to TetraLogical's compatibility notes, updated on October 13, 2026.

Keep the legend short, then, and write labels that make sense on their own, without repeating the legend in each one.

Yes, when a component or a CMS won't let you use a fieldset. Give the container role="group" and name it with aria-labelledby, pointing to the id of the visible heading, or with aria-label. For radio buttons, use role="radiogroup".

The native fieldset is still the first choice. It already has the group role, so there's no need to add it. A single group wrapped around the whole form isn't what the role is meant for. A group's name follows the same rules as any accessible name.

Yes. Inside a fieldset, the HTML specification only allows the legend as the first child. The test of WCAG technique H71 also checks that it's there. Put it right after the opening tag, before any heading, text or field.