HTML Reference ยท Forms
The <fieldset> element
Reference for the HTML <fieldset> element: grouping related form controls under a legend, disabling a whole group at once, accessibility notes and technical details.
The <fieldset> element groups related form controls together, such as the parts of an address or a set of radio buttons. Its first child can be a <legend> that names the group. Browsers draw a border around the group by default and set the legend into the top edge.
<fieldset> <legend>Delivery speed</legend> <label><input type="radio" name="speed" value="standard"> Standard</label> <label><input type="radio" name="speed" value="express"> Express</label> </fieldset>
Try it
While the gift group is disabled, its controls can't be focused or edited and their values are left out of the submitted data.
Attributes
| Attribute | Values | Description |
|---|---|---|
disabled |
Boolean | Disables every form control inside the fieldset, except controls inside its first <legend>. |
form |
ID of a <form> |
Associates the fieldset with a form elsewhere in the document. It does not move the controls inside it. |
name |
Text | A name for scripts, available through form.elements. The fieldset itself sends no data. |
It also accepts the global attributes.
Usage notes
- Use it for radio and checkbox groups. The legend acts as the question ("Delivery speed") and each label as an answer. Screen readers announce the legend when focus enters the group, so users hear the context.
- Keep legends short. Some screen readers repeat the legend for every control in the group.
legendmust come first. Only a<legend>that is the first child of the fieldset captions it.disabledis inherited. One attribute switches off a whole section, which is handy for "same as billing address" patterns. Controls inside the first legend stay usable, so you can put a toggle there.- Not every group needs one. A single text field doesn't need a fieldset. Use it where controls only make sense together.
- Styling. The default border, padding and margin can be reset with CSS (
border: 0; padding: 0; margin: 0;). Fieldsets have some layout quirks in older browsers, but flex and grid layouts work in current ones.
Technical summary
| Content categories | Flow content, palpable content; form-associated: listed |
| Permitted content | Optionally a <legend> element, followed by flow content |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts flow content |
| Implicit ARIA role | group |
| DOM interface | HTMLFieldSetElement |
| Default display | block (with a border, padding and a small margin) |
Browser support
Supported in every browser.
Related
<legend>โ the caption for a fieldset<form>โ the form that holds the controls<label>โ names for individual controls- Lesson: Labels, Fieldsets and Legends
- Lesson: Checkboxes and Radio Buttons