<legend> Element
Technical Summary
The legend element represents a caption for the remaining contents of its parent fieldset. When its parent is an optgroup, it represents the label for that option group.
In a normal fieldset, place legend as the first child. This is not only a way to put text over a visual border: it affects group semantics, the disabled boundary, and accessibility mappings.
Definition / Contexts
| Item | Specification summary |
|---|---|
| Categories | None |
| Contexts | The first child of a fieldset; in a customizable select, the first child of an optgroup |
| Content model | With a fieldset parent, phrasing content optionally intermixed with heading content. With an optgroup parent in a customizable select, phrasing content without interactive content or a specified tabindex. |
| Content attributes | Global attributes only |
| Tag omission | Neither the start tag nor the end tag is omissible |
| DOM interface | HTMLLegendElement, with a readonly form IDL attribute |
legend is not a generic heading that can be placed anywhere. Its parent and position are part of the specification context. Use h1–h6 and other heading structures for document headings.
Fieldset caption
<fieldset>
<legend>Contact method</legend>
<label><input type="radio" name="contact" value="email"> Email</label>
<label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>
Here, legend supplies the caption for the group, while each label supplies the name of an individual control. A legend does not, by itself, complete the label for each radio button.
| Structure | Name or meaning supplied | Example |
|---|---|---|
fieldset | Represents a group of related controls | The complete set of contact choices |
legend | Caption for the group | Contact method |
label | Label for an individual control | Email or Phone |
Position and content model
In conforming fieldset markup, legend is the first child. Putting an explanatory div or p before it does not satisfy that positional context.
<!-- Conforming structure -->
<fieldset>
<legend>Delivery method</legend>
<label><input type="radio" name="delivery" value="mail"> Mail</label>
</fieldset>
<!-- The legend is not the first child -->
<fieldset>
<p>Choose a delivery method.</p>
<legend>Delivery method</legend>
</fieldset>
When the parent is a fieldset, the content model allows phrasing content optionally intermixed with heading content. The group caption and the document's heading structure still have different responsibilities, so include heading content only when the information architecture and assistive-technology presentation have been considered.
Optgroup boundary
<!-- Customizable-select context -->
<select name="standard">
<optgroup>
<legend>Specifications</legend>
<option value="html">HTML Standard</option>
<option value="dom">DOM Standard</option>
</optgroup>
</select>
The current HTML Standard also permits a first-child legend in an optgroup within a customizable select. Its text is used as the option group's label. Traditional select implementations also use the optgroup label attribute. Do not treat the rendering of a customizable select and a conventional select as the same implementation boundary.
Disabled propagation boundary
<fieldset disabled>
<legend>Not available yet</legend>
<label><input name="plan" value="basic"> Basic</label>
</fieldset>
A fieldset[disabled] makes descendant form controls disabled except for controls that are descendants of the first legend child. This exception is a boundary for descendant controls; it does not turn the legend element itself into an enabled form control.
| Position | What to verify |
|---|---|
| Outside the first legend | Descendant form controls are subject to the disabled condition |
| Inside the first legend | Exception to this fieldset's disabled propagation; verify any control there separately |
| A legend that is not first | Do not apply the first-legend explanation to non-conforming fieldset structure |
DOM Interface
HTMLLegendElement's form IDL attribute returns the same form owner as its parent fieldset when the parent is a fieldset. It returns null otherwise.
const legend = document.querySelector('fieldset > legend');
legend.form;
// The parent fieldset's form owner, or null
legend instanceof HTMLLegendElement;
// true
| API | Meaning | Boundary |
|---|---|---|
form | Returns the legend's form owner | Same as fieldset.form for a fieldset parent; null otherwise |
HTMLLegendElement | DOM interface for a legend element | Does not make the legend itself a form control |
Rendering and accessibility
User agents have special rendering rules that relate the fieldset border to its first legend. CSS that changes the border, position, float, or display can therefore produce visual differences, but a pseudo-element or generic text cannot replace the meaning of a real legend.
HTML-AAM gives legend no corresponding ARIA role and uses it in the label relationship with its parent fieldset. The fieldset follows group mapping, and its first rendered legend is relevant to the group name. If the legend is hidden from the accessibility tree, it does not provide the accessible name for its parent fieldset.
Fact / Evidence
Normative claims and implementation observations are separated by parent, position, conditions, and verification state.
| Type | Fact / Claim | Conditions / Scope | Status | Evidence |
|---|---|---|---|---|
| SPEC | legend represents a caption for the remaining contents of its parent fieldset. | First child of a fieldset. | Reviewed | HTML Standard: the legend element |
| SPEC | legend can represent the label of an option group whose parent is an optgroup in a customizable select. | First child of optgroup; includes the relationship with the label attribute. | Reviewed | HTML Standard: the optgroup element |
| SPEC | The permitted parent contexts and content model differ between fieldset and optgroup in a customizable select. | Fieldset allows phrasing content and optional heading content; optgroup excludes interactive content and specified tabindex. | Reviewed | HTML Standard: contexts and content model |
| SPEC | HTMLLegendElement.form returns the parent fieldset's form owner or null. | Result depends on whether the parent is a fieldset. | Reviewed | HTML Standard: HTMLLegendElement |
| SPEC | Descendant form controls in a disabled fieldset are disabled except those inside the first legend child. | First legend, nested fieldsets, and controls inside the legend. | Reviewed | HTML Standard: disabled attribute |
| AAM | legend has no corresponding ARIA role and participates in the label relationship with its parent fieldset. | HTML-AAM legend / fieldset mapping; the fieldset name relates to its first rendered legend. | Specification reviewed | HTML-AAM: legend / fieldset |
Evidence
- HTML Standard: The legend element — meaning, contexts, content model, attributes, and DOM interface
- HTML Standard: The optgroup element — option-group labeling through legend and the label attribute
- HTML Standard: Enabling and disabling form controls — the first-legend disabled boundary
- HTML Accessibility API Mappings: legend — legend role and its label relationship with fieldset
- HTML Accessibility API Mappings: fieldset — group mapping and the first rendered legend
Implementation Evidence
Browser behavior, WPT results, and accessibility observations are tracked separately from normative claims. Unrun items are not treated as reviewed.
Measured fixture / environment: The fixture included a normal fieldset, a first legend, controls inside and outside the legend, a disabled fieldset, and a fieldset with a form owner; DOM and form APIs were measured in Chrome 152.0.0.0 (HeadlessChrome / Windows NT 10.0) on 2026-09-13. Rendering, the accessibility tree, optgroup legends, and customizable selects were not run.
| Type | Scope to reproduce | Conditions to record | Status |
|---|---|---|---|
| IMPL | First legend, controls inside and outside fieldset, disabled propagation, and legend.form | Measured result (Chrome 152.0.0.0 / Windows NT 10.0 / 2026-09-13): the regular legend's parent was the fieldset and legend.form returned evidence-form; a legend outside a fieldset returned null. CSS rendering and cross-browser comparison are not covered | Reviewed |
| IMPL | CSS rendering conditions, optgroup legends, and customizable selects | Compare position / float / display, conventional versus customizable selects, and visual results | Pending |
| WPT | Disabled fieldsets, controls inside and outside legend, and optgroup / customizable select coverage | Ran event-propagate-disabled.tentative.html as a related disabled-fieldset test. On 2026-09-15 in Chrome 152.0.0.0 / Windows NT 10.0, 192 of 256 tests passed on wpt.live; 64 could not complete because action_sequence() is not implemented by testdriver-vendor.js. Legend-specific tests remain unrun. | Partial (192/256 pass) |
| AAM | Fieldset group, legend-derived name, controls inside legend, and individual control labels | Separate browser accessibility-tree, platform accessibility API, and assistive-technology observations | Pending |
Use the WPT repository for test mapping and HTML-AAM for the accessibility baseline. The related test listed here does not establish complete rendering, AAM, or optgroup legend coverage.
Coverage / Open Issues
- ReviewedFieldset caption, optgroup label, parent and position, content model, and HTMLLegendElement.form at the specification level
- ReviewedThe first-legend exception in disabled fieldsets and the HTML-AAM legend / fieldset mapping
- OpenCross-browser comparisons of legend rendering, CSS conditions, controls inside legend, and nested fieldsets
- OpenImplementation comparison for optgroup legend in customizable selects, WPT execution, platform APIs, and assistive-technology announcements
This is an initial coverage page. It does not claim complete verification of the legend specification, every select implementation, or every browser and assistive technology result.
Related surface
For a beginner-friendly introduction to group captions, see the legend element page in Yugien. The group itself is covered by the fieldset element; form relationships by the form element; option-group labels and disabled boundaries by optgroup; option groups as a selection model by the select element; and individual control names by the label element.