Components
Fieldset
Fieldset is used to group and label fields that naturally belong together, such as date fields or address fields. The component helps organize information, make forms more manageable, and improve accessibility for screen readers.
It is common to get confused between fieldset and field. A good rule of thumb is that fieldset is a set of fields
<fieldset class="ds-fieldset">
<legend class="ds-label">Which fjord arm do you live by?</legend>
<p class="ds-paragraph">The choice will help us improve the content we show you.</p>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="radio"
value="barsnesfjorden"
/>
<label class="ds-label" data-weight="regular">Barsnesfjorden</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="radio"
value="eidsfjorden"
/>
<label class="ds-label" data-weight="regular">Eidsfjorden</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
name="radio"
value="none-of-these"
/>
<label class="ds-label" data-weight="regular">None of these</label>
</ds-field>
</fieldset>const PreviewEn = () => { return ( <Fieldset> <Fieldset.Legend>Which fjord arm do you live by?</Fieldset.Legend> <Fieldset.Description> The choice will help us improve the content we show you. </Fieldset.Description> <Radio label='Barsnesfjorden' name='radio' value='barsnesfjorden' /> <Radio label='Eidsfjorden' name='radio' value='eidsfjorden' /> <Radio label='None of these' name='radio' value='none-of-these' /> </Fieldset> ); }; render(<PreviewEn />)
Usage
Use ds-fieldset on the <fieldset> element, and place <legend> and <ds-field> elements inside.
<fieldset class="ds-fieldset">
<legend class="ds-label">Do you accept the terms?</legend>
<!-- your fields -->
</fieldset>
Examples
With checkbox or radio
Build the group with checkbox or radio as children of <fieldset>. This also applies when the group has only one element.
<fieldset class="ds-fieldset">
<legend class="ds-label">Do you accept the terms?</legend>
<ds-field class="ds-field">
<input class="ds-input" type="checkbox" value="agree"/>
<label class="ds-label" data-weight="regular">Yes, I accept</label>
</ds-field>
</fieldset>const WithCheckboxEn = () => { return ( <Fieldset> <Fieldset.Legend>Do you accept the terms?</Fieldset.Legend> <Checkbox label='Yes, I accept' value='agree' /> </Fieldset> ); }; render(<WithCheckboxEn />)
With validation message
When a validation message with data-field="validation" is a child of <fieldset>, the containing <ds-field> elements will
automatically be updated to reflect the validation state.
<fieldset class="ds-fieldset">
<legend class="ds-label">Do you accept the terms?</legend>
<ds-field class="ds-field">
<input class="ds-input" type="checkbox" value="agree"/>
<label class="ds-label" data-weight="regular">Yes, I accept</label>
</ds-field>
<p class="ds-validation-message" data-field="validation">You must accept the terms</p>
</fieldset>const WithValidationEn = () => { return ( <Fieldset> <Fieldset.Legend>Do you accept the terms?</Fieldset.Legend> <Checkbox label='Yes, I accept' value='agree' /> <ValidationMessage>You must accept the terms</ValidationMessage> </Fieldset> ); }; render(<WithValidationEn />)
Multiple field types
A fieldset can also group other fields, for example field with input and select.
<fieldset class="ds-fieldset">
<legend class="ds-label">Personal information</legend>
<p class="ds-paragraph">Fill in your personal information below.</p>
<ds-field class="ds-field">
<label class="ds-label">First name</label>
<input class="ds-input" type="text"/>
</ds-field>
<ds-field class="ds-field">
<label class="ds-label">Gender</label>
<select class="ds-input">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</ds-field>
</fieldset>const WithFieldsEn = () => { return ( <Fieldset> <Fieldset.Legend>Personal information</Fieldset.Legend> <Fieldset.Description> Fill in your personal information below. </Fieldset.Description> <Field> <Label>First name</Label> <Input /> </Field> <Field> <Label>Gender</Label> <Select> <Select.Option value='male'>Male</Select.Option> <Select.Option value='female'>Female</Select.Option> <Select.Option value='other'>Other</Select.Option> </Select> </Field> </Fieldset> ); }; render(<WithFieldsEn />)
Readonly
Fields with the readonly attribute are included in the tab order. Users can copy the content but not edit it. Information is included when the form is submitted.
Readonly fields can be confusing for some users. Not everyone will understand why they cannot change the content of the field. We therefore recommend avoiding readonly as much as possible.
<fieldset class="ds-fieldset">
<legend class="ds-label">Which district do you live in?</legend>
<p class="ds-paragraph">Trondheim is divided into four districts</p>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
readOnly=""
name="city"
value="ostbyen"
/>
<label class="ds-label" data-weight="regular">Østbyen</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
readOnly=""
name="city"
value="lerkendal"
/>
<label class="ds-label" data-weight="regular">Lerkendal</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
readOnly=""
name="city"
checked=""
value="heimdal"
/>
<label class="ds-label" data-weight="regular">Heimdal</label>
</ds-field>
<ds-field class="ds-field">
<input
class="ds-input"
type="radio"
readOnly=""
name="city"
value="midtbyen"
/>
<label class="ds-label" data-weight="regular">Midtbyen</label>
</ds-field>
</fieldset>const ReadOnlyEn = () => { return ( <Fieldset> <Fieldset.Legend>Which district do you live in?</Fieldset.Legend> <Fieldset.Description> Trondheim is divided into four districts </Fieldset.Description> <Radio label='Østbyen' value='ostbyen' name='city' readOnly /> <Radio label='Lerkendal' value='lerkendal' name='city' readOnly /> <Radio label='Heimdal' value='heimdal' name='city' readOnly checked /> <Radio label='Midtbyen' value='midtbyen' name='city' readOnly /> </Fieldset> ); }; render(<ReadOnlyEn />)
CSS variables and data attributes
Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.
| Name | Value |
|---|---|
| --dsc-fieldset-description-color | inherit |
| --dsc-fieldset-gap | var(--ds-size-4) |
| Name | Value |
|---|---|
| data-field | description |
React
import { Fieldset, Radio } from '@digdir/designsystemet-react';
<Fieldset>
<Fieldset.Legend>Question</Fieldset.Legend>
<Fieldset.Description>Description</Fieldset.Description>
<Radio label="Option 1" name="radio" value="1" />
<Radio label="Option 2" name="radio" value="2" />
</Fieldset>
FieldsetDescription
- variant
- Description
Adjusts styling for paragraph length
- Type
"long" | "default" | "short"- Default
'default'
- asChild
- Description
Change the default rendered element for the one passed as a child, merging their props and behavior.
- Type
boolean- Default
false
| Name | Type | Default | Description |
|---|---|---|---|
| variant | "long" | "default" | "short" | 'default' | Adjusts styling for paragraph length |
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |