Home HTML Tags <legend> HTML <legend> Tag Definition
Definition and Usage The <legend> element is a caption for its parent <fieldset> . It names a group of related controls so users (and assistive tech) understand what the group is about.
Put <legend> as the first child of the fieldset. Use <label> for each individual control inside the group.
Baseline · Widely available. Not deprecated as an element. Stable across modern browsers since about July 2015.
Deprecated: align. Do not use the old align attribute on <legend>. Position and style the caption with CSS instead.
Newer context. In customizable <select> UIs, <legend> may also appear inside <selectedcontent> — check support before relying on that pattern alone.
Syntax
HTML Syntax <fieldset>
<legend>Group title</legend>
…controls…
</fieldset> Both start and end tags are required. Keep the legend text short and clear.
Reference
Attributes <legend> has no useful modern element-specific attributes. Prefer globals; avoid deprecated align.
Attribute Description Try it (none required) A bare <legend> with text captions the fieldset Try itGlobal attributes id, class, lang, and other globals Try italignDeprecated — once aligned the caption; do not useAvoid Use <label> too legend names the group; label names each control Try it
Try it
Live Preview Edit the caption text and apply it to a real <legend>.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Radio group 2. Contact group 3. legend vs label Example 1 — Caption a Radio Group Use legend to name the choice set; use label for each option.
<fieldset>
<legend>Favorite monster</legend>
<input type="radio" id="kraken" name="monster" value="K">
<label for="kraken">Kraken</label>
<input type="radio" id="sasquatch" name="monster" value="S">
<label for="sasquatch">Sasquatch</label>
</fieldset> How It Works Wrap related controls in <fieldset>.Put <legend> first with a clear group title.Share one name on the radios so they act as one choice.Link each label with matching for / id.Example 2 — Contact Details Group Caption a set of text fields that belong together.
<fieldset>
<legend>Contact details</legend>
<label for="email">Email</label>
<input id="email" name="email" type="email">
<label for="phone">Phone</label>
<input id="phone" name="phone" type="tel">
</fieldset> How It Works Group the fields that share one purpose.Caption with legend (“Contact details”).Label each input so every field has its own name.Use sensible type values (email, tel).Example 3 — legend vs label One caption for the group; one label per control.
<fieldset>
<legend>Notification preference</legend>
<input type="radio" id="email-n" name="notify" value="email">
<label for="email-n">Email</label>
<input type="radio" id="sms-n" name="notify" value="sms">
<label for="sms-n">SMS</label>
</fieldset> How It Works legend answers “What is this group?”label answers “What is this control?”Do not replace per-control labels with only a legend.Keep both for clear, accessible forms. Edge Cases & Pitfalls Most legend bugs are wrong placement, missing labels, or presentational attributes.
structure Not the first child of fieldset Put <legend> first inside <fieldset>. Content before it is incorrect (MDN).
a11y Legend alone is not enough Still label each input or radio. Legend captions the group only.
deprecated Do not use align Presentational align is obsolete. Use CSS for placement and look.
nesting One legend per fieldset Use nested fieldsets (each with its own legend) for subgroups — not multiple legends in one fieldset.
empty Empty or vague captions Write a meaningful title (“Billing address”), not filler like “Group 1”.
Compatibility
Browser Support The <legend> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<legend> Widely available since about July 2015. Pairing with fieldset works everywhere. Customizable select + selectedcontent support varies.
98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported <legend> Widely supported
Bottom line: Safe for everyday forms. Keep legend first in fieldset; treat selectedcontent usage as progressive enhancement.
Remember
Key Takeaways Role: <legend> captions a <fieldset> group.
Position: make it the first child of the fieldset.
Pair with labels: legend for the group, label for each control.
Deprecated: never use align on legend.
One line: first child of <fieldset> — a clear <legend> for the group.
UA style
Default CSS Settings Browsers often place the legend on the fieldset border. Exact UA styles vary:
legend {
display: block; /* typical */
padding-inline: 2px;
/* often sits on the fieldset border */
}
fieldset {
border: 1px groove; /* approximate UA look */
margin: 0 2px;
padding: 0.35em 0.75em;
} You can restyle both with CSS. Keep the caption readable and associated with the group.
Frequently Asked Questions What is the HTML legend tag used for? The legend element provides a caption for its parent fieldset, naming a group of related form controls for sighted users and assistive technologies.
Where must legend appear? As the first child of a fieldset. Put the caption first, then the inputs and labels.
What is the difference between legend and label? legend captions the whole group. label associates with one control (for example one radio or text input).
Does legend have its own attributes? No useful modern element-specific attributes. It supports Global Attributes. The old align attribute is deprecated.
Can I put a heading inside legend? Yes. Phrasing content and heading elements (h1–h6) are allowed inside legend when you need stronger structure.
What happens if fieldset is disabled? Disabling the fieldset disables its descendant controls. The legend remains the group caption.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful
Helpful Share Copy link Suggestion