HTML <legend> Tag

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

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.

HTML Syntax

syntax.html
<fieldset>
  <legend>Group title</legend>
  …controls…
</fieldset>

Both start and end tags are required. Keep the legend text short and clear.

Attributes

<legend> has no useful modern element-specific attributes. Prefer globals; avoid deprecated align.

AttributeDescriptionTry it
(none required)A bare <legend> with text captions the fieldsetTry it
Global attributesid, class, lang, and other globalsTry it
alignDeprecated — once aligned the caption; do not useAvoid
Use <label> toolegend names the group; label names each controlTry it

Global Attributes

The <legend> tag also supports the Global Attributes in HTML.

Live Preview

Edit the caption text and apply it to a real <legend>.

A real fieldset with legend. Change the caption, then pick a radio.

Fieldset
Choose a size

Caption: Choose a size

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Caption a Radio Group

Use legend to name the choice set; use label for each option.

HTML
<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>
Try It Yourself

How It Works

  1. Wrap related controls in <fieldset>.
  2. Put <legend> first with a clear group title.
  3. Share one name on the radios so they act as one choice.
  4. Link each label with matching for / id.

Example 2 — Contact Details Group

Caption a set of text fields that belong together.

HTML
<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>
Try It Yourself

How It Works

  1. Group the fields that share one purpose.
  2. Caption with legend (“Contact details”).
  3. Label each input so every field has its own name.
  4. Use sensible type values (email, tel).

Example 3 — legend vs label

One caption for the group; one label per control.

HTML
<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>
Try It Yourself

How It Works

  1. legend answers “What is this group?”
  2. label answers “What is this control?”
  3. Do not replace per-control labels with only a legend.
  4. 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”.

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.

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.

Default CSS Settings

Browsers often place the legend on the fieldset border. Exact UA styles vary:

default.css
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

The legend element provides a caption for its parent fieldset, naming a group of related form controls for sighted users and assistive technologies.
As the first child of a fieldset. Put the caption first, then the inputs and labels.
legend captions the whole group. label associates with one control (for example one radio or text input).
No useful modern element-specific attributes. It supports Global Attributes. The old align attribute is deprecated.
Yes. Phrasing content and heading elements (h1–h6) are allowed inside legend when you need stronger structure.
Disabling the fieldset disables its descendant controls. The legend remains the group caption.

Next: li

Learn list items inside ul, ol, and menu.

li tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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