The <fieldset> & <legend> elements
The <fieldset> tag groups related controls in a form, such as a set of radio buttons or the parts of an address, and draws a border around them by default. Its first child, <legend>, is the caption for the group. Screen readers announce the legend with each field, and the disabled attribute turns off every control in the group at once.
Last updated: October 3, 2026
Quick facts
| Category | Flow content, form-associated (listed), palpable content |
| Content model | An optional <legend> first, followed by flow content |
| Tag omission | Neither the start nor the end tag can be omitted, for either element |
| Permitted parents | <fieldset>: any element that accepts flow content. <legend>: a <fieldset>, as its first child |
| DOM interfaces | HTMLFieldSetElement, HTMLLegendElement |
Syntax
Live example
Edit the code below and watch the preview update instantly.
Attributes
<fieldset>
| Attribute | Description |
|---|---|
| disabled | Turns off every form control inside the group (controls inside the <legend> stay active) |
| name | A name for the group, used in scripts |
| form | The id of a <form> to belong to, if the fieldset sits outside it |
<legend>
| Attribute | Description |
|---|---|
| — | Only the global attributes apply. |
Common examples
A group of radio buttons
The classic use: the legend asks the question, each radio button is an answer.
A checkout form split into sections
Long forms are easier to fill in when related fields are grouped under clear legends.
Turning a whole group on or off
The disabled attribute on the fieldset disables every field inside it at once.
<fieldset> vs <div>
A <div> can group form fields visually, but it tells assistive technology nothing. A <fieldset> with a <legend> creates a named group: when a screen reader user moves into it, they hear the legend (“Preferred contact method”) before each option, so a lone “Email” radio button makes sense.
Use a fieldset whenever several fields answer one question or belong to one topic. Use a div when you just need a wrapper for layout. Remember that the default border can be removed with CSS — the meaning stays.
| <fieldset> | <div> | |
|---|---|---|
| Group name for screen readers | Yes (<legend>) | No |
| Disable all fields at once | Yes | No |
| Default style | Border + legend | None |
Common mistakes to avoid
- Radio buttons without a fieldset. Screen reader users then hear “Yes” and “No” with no idea what the question was.
- Using a heading instead of a legend. A heading above the group isn’t connected to the fields; the legend is.
- Wrapping a single field in a fieldset. One field just needs a <label>.
- Placing the legend anywhere but first. The
<legend>must be the first child of the fieldset.
Accessibility & SEO tips
- Keep legends short — screen readers may repeat them for every field in the group.
- Fieldsets are the clearest way to group radio buttons and checkboxes, which also makes forms easier for everyone to scan.
- Disabled fields are skipped when the form is submitted, so don’t disable a group that contains data you still need.
Browser support
Supported in every browser, including Chrome, Edge, Firefox, Safari and their mobile versions — it has been part of HTML since the very first versions.
Tutorial: HTML forms tutorial