Skip to main content
Components

Tabs

Tabs can be a helpful way of letting users quickly switch between related information. From tablet width up they are tabs; below it, and without JavaScript, they are a list of links to every panel.

Read the Design System guidance for tabs

Import

import * as Tabs from 'govuk-react/tabs';

Examples

Default

Code
<Tabs.Composite items={items} />

Radios

Code
<Tabs.RadiosComposite items={items} name="cases-radios" />

With parts

Code
<Tabs.Root defaultValue="parts-past-week">
  <Tabs.Title />
  <Tabs.List>
    {items.map((item) => (
      <Tabs.ListItem key={item.id} value={`parts-${item.id}`}>
        <Tabs.Tab value={`parts-${item.id}`}>{item.label}</Tabs.Tab>
      </Tabs.ListItem>
    ))}
  </Tabs.List>
  {items.map((item) => (
    <Tabs.Panel key={item.id} value={`parts-${item.id}`}>
      {item.panel}
    </Tabs.Panel>
  ))}
</Tabs.Root>

Controlled

Code
<ControlledTabs />

API reference

Tabs.Root

Tabs can be a helpful way of letting users quickly switch between related information.

As in govuk-frontend, without JavaScript the tabs are a list of links to every panel. Use Tab and Panel inside it. Each tab's value is its panel's id.

PropType
onValueChange

Called when the user selects a tab.

(value: string, details: ChangeDetails) => void
name

The panels' radio group name. Defaults to a generated one.

string
value

The selected tab's value, to control the tabs.

string
defaultValue

The tab selected at first, when uncontrolled. Defaults to the first tab.

string

Tabs.RadiosRoot

Tabs that switch panels without JavaScript too, through a hidden radio in each panel. Use RadioTab and RadioPanel inside it. Each tab's value is its panel's id.

PropType
onValueChange

Called when the user selects a tab.

(value: string, details: ChangeDetails) => void
name

The panels' radio group name. Defaults to a generated one.

string
valuestring
defaultValuestring

Tabs.Composite

The tabs, with a tab and panel for each item. Without JavaScript, a list of links to every panel.

PropType
defaultValue

The tab selected at first, when uncontrolled. Defaults to the first tab.

string
onValueChange

Called when the user selects a tab.

(value: string, details: ChangeDetails) => void
name

The panels' radio group name. Defaults to a generated one.

string
value

The selected tab's value, to control the tabs.

string
title

The heading shown above the list of links when the tabs aren't shown. Defaults to "Contents".

ReactNode
itemsRequiredCompositeItem[]

Tabs.List

No props of its own. Other props are passed to the element it renders.

Tabs.ListItem

PropType
selectedboolean

Tabs.Panel

A panel in a Root.

PropType
selectedboolean
valueRequired

Its tab's value, which is the panel's id.

string
name

The panels' radio group name. Set by Root: pass it to a panel rendered without one, such as in an island.

string

Tabs.RadioPanel

A panel in a RadiosRoot, shown without JavaScript only while its tab is chosen.

PropType
selectedboolean
valueRequired

Its tab's value, which is the panel's id.

string
name

The panels' radio group name. Set by Root: pass it to a panel rendered without one, such as in an island.

string

Tabs.RadiosComposite

The tabs, with a tab and panel for each item. They switch panels without JavaScript too.

PropType
onValueChange

Called when the user selects a tab.

(value: string, details: ChangeDetails) => void
name

The panels' radio group name. Defaults to a generated one.

string
title

The heading shown above the list of tabs when they aren't styled as tabs. Defaults to "Contents".

ReactNode
itemsRequiredCompositeItem[]
value

The selected tab's value, to control the tabs.

string
defaultValue

The tab selected at first, when uncontrolled. Defaults to the first tab.

string

Tabs.RadioTab

A tab in a RadiosRoot: a label for its panel's radio.

PropType
valueRequired

Its panel's value, which is the panel's id.

string
name

The panels' radio group name. Set by RadiosRoot: pass it to a tab rendered without one, such as in an island.

string

Tabs.Tab

A tab in a Root: a link to its panel.

PropType
valueRequired

Its panel's value, which is the panel's id.

string

Tabs.Title

No props of its own. Other props are passed to the element it renders.