Skip to main content

What are you looking for?

Try searching for…

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

HTML

Press Enter to start editing
Unable to parse html
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.

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.

Multiple field types

A fieldset can also group other fields, for example field with input and select.

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.

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.

CSS Variables
NameValue
--dsc-fieldset-gapvar(--ds-size-4)
--dsc-fieldset-description-colorvar(--ds-color-neutral-text-subtle)
Data Attributes
NameValue
data-fielddescription

React

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
NameTypeDefaultDescription
variant"long" | "default" | "short"'default'

Adjusts styling for paragraph length

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

Edit this page on github.com (opens in a new tab)