fieldset
Groups related form controls together with an optional caption. Essential for organizing complex forms and providing accessible groupings for screen readers.
When to Use
- Grouping related form fields (e.g., billing address, shipping address)
- Radio button or checkbox groups that belong together
- Sections of a multi-part form
- Any time you need to provide a group label for accessibility
Always include a legend as the first child to provide a caption for the group.
Basic Usage
A fieldset with a legend creates a visually and semantically grouped form section.
Code
Style Variants
Default (Bordered)
Standard fieldset with a visible border and legend that breaks the border line.
.minimal
Borderless fieldset for subtle grouping. The legend appears as a heading.
Code
Radio Button Groups
Fieldset is essential for grouping radio buttons. Screen readers will announce the legend before each radio option.
Code
Checkbox Groups
Group related checkboxes together to indicate they form a set.
Nested Fieldsets
Fieldsets can be nested for complex forms with sub-groupings.
Disabled Fieldset
The disabled attribute on a fieldset disables all form controls within it.
Code
With form-field
Combine fieldsets with the form-field custom element for enhanced form controls.
Accessibility Notes
- Always include a legend: The legend provides the accessible name for the group
- Legend must be first child: For proper rendering, legend must be the first element inside fieldset
- Screen reader behavior: The legend is announced before each control in the group
- Required for radio groups: Radio buttons should always be in a fieldset for accessibility
- Avoid nesting too deep: Limit nesting to maintain comprehension
CSS Reference
Related Elements
- legend - Caption for the fieldset (required first child)
- form - Container for fieldsets
- input - Form controls within fieldsets
- form-field - Enhanced form field wrapper