If you answer yes, we store and analyse information that helps us improve the website. You can change your choice at any time at the bottom of the page. More about what we store and why.

We also store necessary information that cannot be opted out of. This makes the website work and keeps it secure.

Skip to main content

What are you looking for?

Try searching for…

Components

Tabs

Tabs allow users to navigate between related sections of content, with only one section visible at a time. This is an effective way to organize and present related content on the same page.

Press Enter to start editing
<ds-tabs class="ds-tabs">
  <ds-tablist>
    <ds-tab
      aria-controls="_R_0_-value1"
      aria-selected="true"
      data-value="value1"
      role="tab"
    >Tab 1</ds-tab>
    <ds-tab
      aria-controls="_R_0_-value2"
      aria-selected="false"
      data-value="value2"
      role="tab"
    >Tab 2</ds-tab>
    <ds-tab
      aria-controls="_R_0_-value3"
      aria-selected="false"
      data-value="value3"
      role="tab"
    >Tab 3</ds-tab>
  </ds-tablist>
  <ds-tabpanel id="_R_0_-value1">content 1</ds-tabpanel>
  <ds-tabpanel id="_R_0_-value2">content 2</ds-tabpanel>
  <ds-tabpanel id="_R_0_-value3">content 3</ds-tabpanel>
</ds-tabs>
const Preview = () => {
  return (
    <Tabs defaultValue='value1'>
      <Tabs.List>
        <Tabs.Tab value='value1'>Tab 1</Tabs.Tab>
        <Tabs.Tab value='value2'>Tab 2</Tabs.Tab>
        <Tabs.Tab value='value3'>Tab 3</Tabs.Tab>
      </Tabs.List>
      <Tabs.Panel value='value1'>content 1</Tabs.Panel>
      <Tabs.Panel value='value2'>content 2</Tabs.Panel>
      <Tabs.Panel value='value3'>content 3</Tabs.Panel>
    </Tabs>
  );
};

render(<Preview />)

Usage

We extend u-tabs (u-elements.github.io), which is a web component that implements tabs. Add the class name ds-tabs on the <ds-tabs> element to get Designsystemet styling.

We recommend using <ds-tabs>, and not building your own tabs from scratch, to ensure good accessibility and functionality.

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-tabs-content-paddingvar(--ds-size-4) var(--ds-size-5)
--dsc-tabs-list-border-bottom-stylesolid
--dsc-tabs-list-border-bottom-widthvar(--ds-border-width-default)
--dsc-tabs-list-border-colorvar(--ds-color-neutral-border-subtle)
--dsc-tabs-tab-colorvar(--ds-color-neutral-text-subtle)
--dsc-tabs-tab-color--hovervar(--ds-color-neutral-text-default)
--dsc-tabs-tab-color--selectedvar(--ds-color-text-subtle)
--dsc-tabs-tab-paddingvar(--ds-size-3) var(--ds-size-5)

No relevant data attributes found.

React

Example of controlled

Example of panel reuse

To speed up your application, you can reuse a single tabpanel and instead swap the content inside:

Tabs

value
Description

Controlled state for `Tabs` component

Type
string
Default
undefined
defaultValue
Description

Default selected tab value

Type
string
Default
undefined
onChange
Description

Callback with selected `TabItem` `value`

Type
((value: string) => void)
Default
undefined
NameTypeDefaultDescription
valuestringundefined

Controlled state for `Tabs` component

defaultValuestringundefined

Default selected tab value

onChange((value: string) => void)undefined

Callback with selected `TabItem` `value`

TabsPanel

value
Description

When this value is selected as the current state, render this `TabsPanel` component. Must match the `value` of a `Tabs.Tab` component.

Type
string
NameTypeDefaultDescription
valuestring-

When this value is selected as the current state, render this `TabsPanel` component. Must match the `value` of a `Tabs.Tab` component.

TabsTab

value
Description

Unique value that will be set in the `Tabs` components state when the tab is activated

Type
string
NameTypeDefaultDescription
valuestring-

Unique value that will be set in the `Tabs` components state when the tab is activated

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