HTML <fieldset> Tag

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Controls

What You’ll Learn

By the end of this tutorial, you’ll group related form controls with semantic, accessible fieldsets.

In web forms, the <fieldset> tag plays a pivotal role in structuring and organizing form elements. This guide covers syntax, attributes, accessibility, and best practices for beginners and web developers alike.

01

Core Syntax

Wrap related controls in <fieldset> with a <legend>.

02

Form Grouping

Organize personal info, contact details, and payment sections.

03

disabled Attribute

Disable an entire group of controls at once.

04

legend Caption

Give each group a clear, accessible title.

05

CSS Styling

Style borders and legends for polished forms.

06

Accessibility

Help screen readers understand form structure.

What Is the <fieldset> Tag?

The fieldset element (<fieldset>) is a container designed explicitly for grouping and structuring form-related elements. It is often paired with <legend> to provide a caption or title for the enclosed controls.

💡
Always add a legend

Every fieldset should include a legend as its first child. The legend names the group for sighted users and assistive technologies.

Browsers render a visible border around fieldsets by default. You can customize or remove it with CSS while keeping the semantic grouping for accessibility.

📝 Syntax

Use opening and closing <fieldset> tags. Place a <legend> first, then your form controls:

syntax.html
<fieldset>
  <legend>Your Caption Here</legend>
  <!-- Your form elements go here -->
</fieldset>

Syntax Rules

  • Place <legend> as the first child of fieldset.
  • Group only related form controls inside one fieldset.
  • Use nested fieldsets sparingly—keep form structure flat when possible.
  • The disabled attribute on fieldset disables all nested controls.

⚡ Quick Reference

PatternCode SnippetNotes
Basic group<fieldset><legend>...</legend>Legend required for a11y
Disable group<fieldset disabled>Disables all inner controls
With form<form><fieldset>...</fieldset></form>Most common pattern
Styled groupclass="form-group"CSS hook on fieldset
Pair element<legend>Caption for the group
Default styleBorder + paddingBrowser user-agent styles

⚖️ <fieldset> vs <div>

Both can wrap form fields visually, but only fieldset carries semantic meaning:

Feature<fieldset><div>
Semantic roleForm groupGeneric container
Caption element<legend>Use heading or aria-labelledby
Disable all controlsdisabled on fieldsetDisable each control individually
AccessibilityBuilt-in group semanticsRequires extra ARIA markup

⚖️ <fieldset> and <legend>

These elements work together as a labeled form group:

ElementRoleWhen to use
<fieldset>Group containerWrap related inputs, selects, textareas, radios
<legend>Group captionName the section (first child of fieldset)
TogetherLabeled groupPersonal info, shipping, payment sections
Without legendInvalid patternAlways include legend for accessibility

🧰 Attributes

The <fieldset> tag supports these key attributes plus global attributes such as class and id:

disabled Boolean

Disables all form controls inside the fieldset. Users cannot edit or submit them.

<fieldset disabled>
name Forms

Names the fieldset for form submission when used with certain APIs.

name="shipping"
form Optional

Associates the fieldset with a form by id, even outside the form element.

form="signup-form"
class / style Global

Style borders, spacing, and backgrounds for consistent form design.

class="form-group"
attributes.html
<fieldset class="form-group" style="border: 1px solid #ccc;" disabled>
  <legend>Disabled Fieldset</legend>
  <!-- Disabled form elements go here -->
</fieldset>

Prefer CSS classes over inline style for reusable form design systems.

Examples Gallery

Personal information, contact details, and disabled fieldset patterns with copy-ready code and live previews.

Live Preview

A fieldset grouping name and email fields:

Account Details

Grouping Form Elements

The primary purpose of <fieldset> is to group related form elements with a shared legend.

grouping-form-elements.html
<fieldset>
  <legend>Personal Information</legend>

  <label for="first-name">First Name</label>
  <input type="text" id="first-name" name="firstName">

  <label for="last-name">Last Name</label>
  <input type="text" id="last-name" name="lastName">
</fieldset>
Try It Yourself

📚 Common Use Cases

Use <fieldset> to group personal information, contact details, shipping vs billing addresses, payment methods, survey question sections, and radio/checkbox option groups with a shared legend.

Providing Structure

Using <fieldset> and <legend> adds structure and clarity, making forms more accessible and user-friendly.

providing-structure.html
<fieldset>
  <legend>Contact Information</legend>

  <label for="email">Email</label>
  <input type="email" id="email" name="email">

  <label for="phone">Phone</label>
  <input type="tel" id="phone" name="phone">
</fieldset>
Try It Yourself

Disabled Fieldset

Use the disabled attribute to disable an entire group of form elements at once.

disabled-fieldset.html
<fieldset class="form-group" disabled>
  <legend>Disabled Fieldset</legend>

  <label for="company">Company</label>
  <input type="text" id="company" name="company">
</fieldset>
Try It Yourself

Styling <fieldset> with CSS

Customize borders, spacing, and legend typography for polished forms:

border Group outline
border-radius Rounded groups
legend Caption typography
opacity Disabled state
fieldset-styles.css
/* Form group styling */
fieldset.form-group {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

fieldset.form-group legend {
  font-weight: 600;
  color: #0f172a;
  padding: 0 0.35rem;
}

fieldset[disabled] {
  opacity: 0.65;
  background: #f8fafc;
}

Live styled fieldset

♿ Accessibility

Semantic form grouping helps all users complete forms:

  • Always include legend — screen readers announce the group name when focus enters the fieldset.
  • Group related controls only — do not mix unrelated fields in one fieldset.
  • Use disabled on fieldset — disables the whole group consistently for assistive tech.
  • Pair labels with inputs — every control inside the fieldset still needs its own label.

🧠 How <fieldset> Works

1

Author creates a group

Wrap related controls in fieldset and add legend.

Markup
2

Browser draws the group

Default border and legend placement visually separate the section.

Rendering
3

Assistive tech reads legend

Screen readers expose the group name when users tab into controls.

Accessibility
=

Clear, structured forms

Users understand form sections and submit data with confidence.

Universal Browser Support

The <fieldset> element is fully supported in all browsers, including legacy Internet Explorer.

Baseline · Since HTML 4

Form grouping that works everywhere

From legacy Internet Explorer to the latest mobile browsers — fieldset and legend are foundational form elements.

100% Core tag support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
<fieldset> tag 100% supported

Bottom line: Ship semantic form groups with confidence. The <fieldset> element is safe to use in every production environment today.

Conclusion

Incorporating the <fieldset> tag into your HTML forms enhances organization and usability. By structuring forms effectively with legends, you contribute to a better user experience and streamline data submission.

Always pair fieldset with legend, use CSS classes for consistent styling, and leverage disabled when an entire section should be unavailable.

💡 Best Practices

✅ Do

  • Always include a legend inside fieldset
  • Use CSS classes for consistent form group styling
  • Use disabled to disable an entire group at once
  • Group only related form controls together

❌ Don’t

  • Skip the legend element
  • Use fieldset purely for visual boxes without semantics
  • Mix unrelated fields in one fieldset
  • Nest fieldsets deeply without clear purpose

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <fieldset>

Bookmark these before you ship — they’ll keep your forms semantic and accessible.

6
Core concepts
🔖 02

legend Required

Caption the group with legend first.

Accessibility
🚫 03

disabled Group

One attribute disables all inner controls.

Attribute
⚖️ 04

Not a div

Semantic grouping beats generic containers.

Comparison
🎨 05

CSS Friendly

Style borders, legend, and disabled states.

Styling
🌐 06

Universal Support

Works in every browser, including legacy IE.

Compatibility

❓ Frequently Asked Questions

It groups related form controls together, typically with a legend caption for structure and accessibility.
legend is the first child of fieldset and names the group. Screen readers announce it when users focus controls inside.
It disables every form control inside the fieldset so users cannot edit or submit those values.
Yes. fieldset can group controls semantically outside a form, though it is most common inside forms.
Yes. fieldset and legend are fully supported in all modern browsers and Internet Explorer.

Build Structured Forms

Group related fields with fieldset and legend in the interactive HTML editor.

Try personal info group →

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.

6 people found this page helpful