HTML <fieldset> Tag

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

Definition and Usage

The <fieldset> element groups related form controls and their <label>s. A nested <legend> provides the caption for that group.

Use it inside a <form> for shipping details, payment choices, preferences, and other related fields. The disabled attribute can turn off every control in the group at once.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015.

Caption = first legend.

The first <legend> nested in the fieldset is the group title. Put it first when you can.

HTML Syntax

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

Both start and end tags are required. Content is an optional <legend>, then flow content (inputs, labels, paragraphs, and so on).

Attributes

The attributes you will use most often on <fieldset>:

AttributeDescriptionTry it
disabledDisables descendant form controls (not editable, not submitted). Controls inside legend stay enabledTry it
nameName associated with the group (does not replace name on inputs)Try it
formAssociates the fieldset with a <form> by id. Prefer nesting inside the form; see edge casesAdvanced

Global Attributes

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

Live Preview

Toggle disabled on a real <fieldset> and try the controls.

Disabling the fieldset turns off the inputs inside (except controls placed in the legend).

Fieldset
Contact

Fieldset is enabled — you can edit the fields.

HTML Examples

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

Example 1 — Basic Group with Legend

Wrap related radios in a fieldset and caption them with legend.

HTML
<form>
  <fieldset>
    <legend>Favorite fruit</legend>

    <input type="radio" id="apple" name="fruit" value="apple">
    <label for="apple">Apple</label><br>

    <input type="radio" id="mango" name="fruit" value="mango">
    <label for="mango">Mango</label>
  </fieldset>
</form>
Try It Yourself

How It Works

  1. Open <fieldset> around the related controls.
  2. Add <legend> first as the group caption.
  3. Place inputs and labels inside the fieldset.
  4. Close the tags so the browser draws the grouped box.

Example 2 — Agreement Checkbox Group

A short fieldset works well for a single related decision.

HTML
<form>
  <fieldset>
    <legend>Do you agree?</legend>
    <input type="checkbox" id="agree" name="agree" value="yes">
    <label for="agree">I agree to the terms</label>
  </fieldset>
</form>
Try It Yourself

How It Works

  1. Caption the decision with <legend>.
  2. Connect label and input with matching for / id.
  3. Keep only related controls in that fieldset.
  4. Let the legend name the group for screen reader users.

Example 3 — Disable a Whole Group

One disabled attribute turns off descendant controls.

HTML
<form>
  <fieldset disabled>
    <legend>Login (disabled)</legend>
    <label for="user">User</label>
    <input id="user" name="user" type="text" value="chris">
    <label for="pwd">Password</label>
    <input id="pwd" name="pwd" type="password" value="secret">
  </fieldset>
</form>
Try It Yourself

How It Works

  1. Add disabled on the <fieldset>.
  2. Descendant inputs become disabled — no edit, no submit, usually grayed out.
  3. Exception: controls inside the <legend> are not disabled by this attribute.
  4. Remove disabled (or toggle it with script) to re-enable the group.

Example 4 — Multiple Named Groups

Split a form into clear sections with separate fieldsets.

HTML
<form>
  <fieldset name="shipping">
    <legend>Shipping</legend>
    <label for="city">City</label>
    <input id="city" name="city" type="text">
  </fieldset>

  <fieldset name="billing">
    <legend>Billing</legend>
    <label for="card">Card last 4</label>
    <input id="card" name="card" type="text" maxlength="4">
  </fieldset>
</form>
Try It Yourself

How It Works

  1. Create one fieldset per topic (Shipping, Billing).
  2. Give each a clear legend.
  3. Optional name on the fieldset names the group in the DOM — inputs still need their own name.
  4. Keep each group focused so users and assistive tech can scan the form.

Edge Cases & Pitfalls

Most fieldset bugs come from missing legends or misunderstanding disabled / form.

a11y

Always add a legend

Without <legend>, the group has a weak accessible name. Put a clear caption first.

disabled

Legend controls stay active

disabled on fieldset does not disable form controls placed inside the legend. Keep interactive controls out of the legend unless that is intentional.

form attr

form on fieldset is easy to misuse

Associating the fieldset with a form by id does not automatically associate every control. Prefer nesting, or set form on the controls themselves.

labels

Still label each control

A legend names the group. Each input still needs its own <label>.

styling

Default border is normal

Browsers draw a groove border and padding. Restyle freely with CSS; legend sits on the start border by default.

Browser Support

The <fieldset> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<fieldset>

Widely available since about July 2015 (and long before as a form grouping element). Chrome, Firefox, Safari, Edge, and Opera all support it fully.

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
<fieldset> Widely supported

Bottom line: Safe to use everywhere for grouping form controls. Pair with legend, and prefer nesting inside form.

Key Takeaways

  • Role: <fieldset> groups related controls; <legend> names the group.
  • disabled: turns off descendant controls in one step (except those in the legend).
  • Structure: nest inside <form> when you can; still label every control.
  • form attribute: advanced and easy to misuse — associate controls carefully.

One line: a good fieldset has a clear legend and only related controls inside.

Default CSS Settings

Typical user-agent styling (exact values can vary by browser):

default.css
fieldset {
  display: block;
  margin-inline: 2px;
  border-width: 2px;
  border-style: groove;
  border-color: ThreeDFace;
  padding-block: 0.35em 0.625em;
  padding-inline: 0.75em;
  min-inline-size: min-content;
}

You may restyle freely. If you set display: flex or grid on the fieldset, an anonymous content box becomes the flex/grid container for the children.

Frequently Asked Questions

The fieldset element groups related form controls and their labels. A nested legend element provides the caption for that group.
It is strongly recommended. The first legend inside the fieldset is the group caption and is important for accessibility. Put legend first when you can.
It disables descendant form controls in one step. They are not editable, do not submit, and usually look grayed out. Controls inside the legend are not disabled by that attribute.
You can set form="form-id" on fieldset, but associating the controls themselves still needs care. Prefer nesting fieldset inside the form, or put form on each control you want linked.
Yes. The name attribute names the group. It does not replace name on individual inputs.
The implicit ARIA role is group. With a legend, assistive tech can announce the group name for the controls inside.

Next: figcaption

Caption a figure with accessible descriptive text.

figcaption 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.

12 people found this page helpful