liveBook · Manning

Legend element

As explained in Architecting Accessibility

The HTML legend element provides a caption for a fieldset.

When related fields appear together, a legend names their group and gives people context as they complete a form. Screen readers can announce the legend alongside each control’s label, such as “Name – Billing Details.” section 6.1.4

Use a legend with a fieldset to make related controls explicit both visually and programmatically. CSS borders alone do not communicate the group to assistive technology users. section 6.1.4

<fieldset> #A
  <legend>Dog size</legend> #B
  <div>
    <input type="radio" name="size" id="small" value="s" checked> #C
    <label for="small">Small</label>
  </div>
  <div>
    <input type="radio" name="size" id="medium" value="m"> #C
    <label for="medium">Medium</label>
  </div>
  <div>
    <input type="radio" name="size" id="large" value="l"> #C
    <label for="large">Large</label>
  </div>
</fieldset>

This example groups dog-size radio choices under the legend “Dog size.” section 6.1.4

How Architecting Accessibility covers it

How deep it goes
Explains the captioning role and how screen readers combine a legend with each control’s label.
Examples
Uses dog-size radio choices and form groups for owner, dog, and complaint details.
What you can do after
Apply it through native HTML to label related controls visually and programmatically.
How it connects
Connects fieldset and legend with labels, radio buttons, checkboxes, and assistive technology.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.