Form groups: <fieldset> + <legend> (and when to use role="group")

If you only visually group related controls (like radios or checkboxes), many assistive technology users won’t reliably get the question that those options answer. Use <fieldset> + <legend> so the group has a real label.

Open: Form groups demo

Checklist

Minimal pattern

<fieldset aria-describedby="shipHint">
  <legend>Shipping speed</legend>
  <div id="shipHint">Choose one.</div>

  <label><input type="radio" name="ship" value="standard"> Standard</label>
  <label><input type="radio" name="ship" value="express"> Express</label>
</fieldset>

If you truly can’t use a fieldset (or your group isn’t a form fieldset), use a container with a label:

<div role="group" aria-labelledby="q1" aria-describedby="q1hint">
  <div id="q1">Notification preferences</div>
  <div id="q1hint">Optional.</div>
  ...controls...
</div>

Pitfalls