Fieldset
Groups related controls behind a border, with the legend notched into it.
| Class | Does what |
|---|---|
fieldset | Bordered group with padding and a bottom margin |
fieldset-legend | Legend, pulled into the border |
Basic
<fieldset class="fieldset">
<legend class="fieldset-legend">Shipping</legend>
<label class="label">
Address
<input type="text" class="input" />
</label>
<label class="label">
City
<input type="text" class="input" />
</label>
</fieldset>
<fieldset>
<legend>Shipping</legend>
<label>
Address
<input type="text" />
</label>
<label>
City
<input type="text" />
</label>
</fieldset>
Composition
Common ways to put this together with other components. The general rules are on Composition.
Grouping filters
One group of filters: a single choice and some that combine, named once by the legend.
<form>
<label class="label">
<p>Search</p>
<input class="input" type="search" />
</label>
<fieldset class="fieldset">
<legend class="fieldset-legend">Filter</legend>
<div class="flex" style="flex-wrap: wrap; align-items: center">
<div class="segmented" role="radiogroup" aria-label="Format" style="margin-bottom: 1rem">
<label class="segmented-item"><input type="radio" name="cfmt" checked /> Any</label>
<label class="segmented-item"><input type="radio" name="cfmt" /> Print</label>
<label class="segmented-item"><input type="radio" name="cfmt" /> Digital</label>
</div>
<label class="label"><input type="checkbox" class="checkbox" /> Free</label>
<label class="label"><input type="checkbox" class="checkbox" checked /> In stock</label>
</div>
</fieldset>
</form>
- Controls: an exclusive choice is a
.segmentedcontrol; choices that combine are checkboxes. The fieldset holds both. - Spacing: the checkbox labels keep their
1rembottom margin, so the segmented control gets the same to share their centre line.
A filter with a range
A range in a filter group, with the current value in the label text.
<fieldset class="fieldset">
<legend class="fieldset-legend">Filter</legend>
<label class="label">
<p class="flex" style="justify-content: space-between"><span>Distance</span><span class="text-secondary">5 miles</span></p>
<input type="range" class="range" min="1" max="20" value="5" style="--range-fill: 21%" />
</label>
<label class="label"><input type="checkbox" class="checkbox" /> Open now</label>
</fieldset>
- Controls: the value sits in the label's
<p>, pushed to the end, so label and value read as one line above the rail. - Text: the value is
.text-secondaryso the name leads.
Disabling a group
Disabling the fieldset disables, and greys, everything inside it.
<form class="card">
<label class="label">
<input type="checkbox" class="checkbox" />
Ship to a different address
</label>
<fieldset class="fieldset" disabled>
<legend class="fieldset-legend">Shipping address</legend>
<label class="label"><p>Street</p><input class="input" /></label>
<label class="label"><p>City</p><input class="input" /></label>
</fieldset>
</form>
- Boundary: a disabled element sets
--chroma: 0for its subtree, so the legend, labels and fields lose colour together.