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.

HTML

Press Enter to start editing
Unable to parse html
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-tab-paddingvar(--ds-size-3) var(--ds-size-5)
--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-content-paddingvar(--ds-size-4) var(--ds-size-5)
--dsc-tabs-list-border-colorvar(--ds-color-neutral-border-subtle)
--dsc-tabs-list-border-bottom-widthvar(--ds-border-width-default)
--dsc-tabs-list-border-bottom-stylesolid

No relevant data attributes found.

React

Example of controlled

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)