Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Forms

The <legend> element

Reference for the HTML <legend> element: captioning a fieldset, how screen readers announce it, headings inside legends, styling notes and technical details.

The <legend> element is the caption of a <fieldset>. It names the group of controls, such as "Billing address" or "How did you hear about us?". It must be the fieldset's first child. Browsers draw it on top of the fieldset's border by default.

HTML
<fieldset>
  <legend>Preferred contact method</legend>
  <label><input type="radio" name="contact" value="email"> Email</label>
  <label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>

Try it

A legend as a question

The second group removes the border and padding, so the legend looks like an ordinary heading while keeping its meaning.

Attributes

This element has no attributes of its own. It accepts the global attributes. (The old align attribute is obsolete; use CSS.)

Usage notes

  • First child only. A legend anywhere else in the fieldset does not caption it.
  • Phrase it as the question or topic. Each control's own label is the answer ("Saturday"); the legend supplies the shared context.
  • Keep it short. Many screen readers read the legend when focus enters the group, and some repeat it for every control.
  • Headings are allowed. A legend may contain a heading, for example <legend><h2>Shipping</h2></legend>, so long forms keep a proper outline.
  • Controls in the legend stay enabled. When the fieldset is disabled, controls inside its first legend remain usable.
  • Styling quirks. The legend's position on the border is special browser rendering. Floating the legend or changing its display takes it out of that position.

Technical summary

Content categories None
Permitted content Phrasing content, optionally intermixed with heading content
Tag omission None; both the start and end tags are required
Permitted parents A <fieldset>, as its first child
Implicit ARIA role No corresponding role
DOM interface HTMLLegendElement
Default display block

Browser support

Supported in every browser.