Skip to main content
WCAGrules
Quick navigation

Group related form fields with fieldset and legend

A fieldset with a legend ties a group of controls to the question they answer. W3C lists it as sufficient for 1.3.1 Info and Relationships, and on its own for 3.3.2 Labels or Instructions. The case it exists for is radio buttons and checkboxes, where individual labels like Yes and No mean nothing without the question above them. It is conditional, though, and the condition is easy to miss. A group whose individual labels already describe each control fully does not need a fieldset to pass. Two markup rules go with it. The legend has to be the first element inside the fieldset, and nesting fieldsets inside fieldsets confuses more than it helps.

How we find it in an audit

Scanners catch a fieldset with no legend. The bigger failure is the radio group with no fieldset at all, which no tool can see, because a styled div holding a bold question looks identical on screen. So we tab into every radio group and every checkbox group and listen for whether the question travels with the options.

How affected users experience it

Tab into an ungrouped radio button and you hear Yes, radio button, one of two. Yes to what is on screen three lines up, attached to nothing, and somebody moving field by field never hears it. With a legend the same control announces as Include VAT in prices, Yes, radio button, and the question rides along with every option in the group.

Passes vs. fails

Passes: a label that stays put. Fails: placeholder-only fields.

Passes

<fieldset>
  <legend>Include VAT in prices?</legend>
  <label><input type="radio" name="vat" value="y"> Yes</label>
  <label><input type="radio" name="vat" value="n"> No</label>
</fieldset>

Fails

<p><strong>Include VAT in prices?</strong></p>
<label><input type="radio" name="vat" value="y"> Yes</label>
<label><input type="radio" name="vat" value="n"> No</label>

How this gets tested

The W3C publishes test rules that define what a checker looks for here.

Other ways to satisfy this rule

52 guides on this site are filed under 1.3.1 Info and Relationships. W3C lists this one as sufficient for that rule when used for making information and relationships conveyed through presentation programmatically determinable, so the condition is part of the test rather than a footnote to it.

This guide is our interpretation of W3C technique H71: Providing a description for groups of form controls using fieldset and legend elements. W3C publishes its techniques as guidance rather than as the standard, and says so on every one of them. The success criterion is what conformance is measured against, and a technique is one documented way to meet it.

Go somewhere useful

Find tools, resources and your workspace.

29 destinations