Live Preview
A fieldset grouping name and email fields:

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.
Wrap related controls in <fieldset> with a <legend>.
Organize personal info, contact details, and payment sections.
Disable an entire group of controls at once.
Give each group a clear, accessible title.
Style borders and legends for polished forms.
Help screen readers understand form structure.
<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.
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.
Use opening and closing <fieldset> tags. Place a <legend> first, then your form controls:
<fieldset>
<legend>Your Caption Here</legend>
<!-- Your form elements go here -->
</fieldset><legend> as the first child of fieldset.disabled attribute on fieldset disables all nested controls.| Pattern | Code Snippet | Notes |
|---|---|---|
| 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 group | class="form-group" | CSS hook on fieldset |
| Pair element | <legend> | Caption for the group |
| Default style | Border + padding | Browser user-agent styles |
<fieldset> vs <div>Both can wrap form fields visually, but only fieldset carries semantic meaning:
| Feature | <fieldset> | <div> |
|---|---|---|
| Semantic role | Form group | Generic container |
| Caption element | <legend> | Use heading or aria-labelledby |
| Disable all controls | disabled on fieldset | Disable each control individually |
| Accessibility | Built-in group semantics | Requires extra ARIA markup |
<fieldset> and <legend>These elements work together as a labeled form group:
| Element | Role | When to use |
|---|---|---|
<fieldset> | Group container | Wrap related inputs, selects, textareas, radios |
<legend> | Group caption | Name the section (first child of fieldset) |
| Together | Labeled group | Personal info, shipping, payment sections |
| Without legend | Invalid pattern | Always include legend for accessibility |
The <fieldset> tag supports these key attributes plus global attributes such as class and id:
disabled BooleanDisables all form controls inside the fieldset. Users cannot edit or submit them.
<fieldset disabled>name FormsNames the fieldset for form submission when used with certain APIs.
name="shipping"form OptionalAssociates the fieldset with a form by id, even outside the form element.
form="signup-form"class / style GlobalStyle borders, spacing, and backgrounds for consistent form design.
class="form-group"<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.
Personal information, contact details, and disabled fieldset patterns with copy-ready code and live previews.
A fieldset grouping name and email fields:
The primary purpose of <fieldset> is to group related form elements with a shared legend.
<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>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.
Using <fieldset> and <legend> adds structure and clarity, making forms more accessible and user-friendly.
<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>Use the disabled attribute to disable an entire group of form elements at once.
<fieldset class="form-group" disabled>
<legend>Disabled Fieldset</legend>
<label for="company">Company</label>
<input type="text" id="company" name="company">
</fieldset>Customize borders, spacing, and legend typography for polished forms:
border Group outlineborder-radius Rounded groupslegend Caption typographyopacity Disabled state/* 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
Semantic form grouping helps all users complete forms:
label.Wrap related controls in fieldset and add legend.
Default border and legend placement visually separate the section.
Screen readers expose the group name when users tab into controls.
Users understand form sections and submit data with confidence.
The <fieldset> element is fully supported in all browsers, including legacy Internet Explorer.
From legacy Internet Explorer to the latest mobile browsers — fieldset and legend are foundational form elements.
Bottom line: Ship semantic form groups with confidence. The <fieldset> element is safe to use in every production environment today.
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.
legend inside fieldsetdisabled to disable an entire group at oncelegend element<fieldset>Bookmark these before you ship — they’ll keep your forms semantic and accessible.
<fieldset> groups related form controls.
Caption the group with legend first.
One attribute disables all inner controls.
AttributeSemantic grouping beats generic containers.
ComparisonStyle borders, legend, and disabled states.
StylingWorks in every browser, including legacy IE.
Compatibilitylegend 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.form, though it is most common inside forms.Group related fields with fieldset and legend in the interactive HTML editor.
6 people found this page helpful