The HTML <fieldset> tag
The HTML <fieldset> element groups related controls in a form, with a <legend> as its caption. The disabled attribute disables every control inside it at once.
Overview
The <fieldset> element groups thematically related form controls — a set of radio buttons, an address block, a payment section — and its first child, a <legend>, gives the group a caption.
This grouping matters most for radio-button sets. There, the <legend> supplies the question ("Choose a shipping method") and each radio its answer, and screen readers announce the legend with each option so the choices make sense in context. Without a fieldset, a lone radio button has no idea what group it belongs to.
A handy bonus: adding the disabled attribute to a <fieldset> disables every control inside it in one go. Browsers draw a border around it by default, which you can restyle or remove freely with CSS.
Syntax
<fieldset>
<legend>Contact preference</legend>
<label><input type="radio" name="c"> Email</label>
<label><input type="radio" name="c"> Phone</label>
</fieldset>
Attributes
The <fieldset> element supports the following attributes, in addition to the global attributes available to every HTML element.
Example
<fieldset style="border:1px solid #cbd5e1;border-radius:6px;">
<legend>Size</legend>
<label><input type="radio" name="s"> Small</label>
<label><input type="radio" name="s"> Large</label>
</fieldset>
Best practices
- Group related controls — especially radio-button sets — in a
<fieldset>. - Make a <legend> the first child to caption the group.
- Use the
disabledattribute to disable all the controls inside at once. - Restyle or remove the default border with CSS to match your design.
Accessibility
A <fieldset> with a <legend> gives a group of controls a shared, announced name — essential for radio-button groups, where screen readers read the legend together with each option ("Contact preference, Email, radio button").
Frequently asked questions
What is the fieldset element for?
Do I need a legend with a fieldset?
How do I disable a group of form fields at once?
disabled attribute to the <fieldset>; all controls inside become disabled.How do I remove the default fieldset border?
border: 0 (and adjust padding/margin) on the <fieldset> with CSS.