Skip to main content

Tabs

Switches between views of the same thing on one page.

In Dense data

See it live​

Start Storybook to see it live: npm run storybook

When to use it​

In Dense data: Views of one record.

  • Use it when: Related views of one object that people move between.
  • Not when: Navigation to other pages (links), or steps of a task (progress).

Instead:

Words​

  • Lead with the object, then the state: "Alert 2041 contained."
  • Use numbers, not words for numbers.
  • One verb per button. No "please", no exclamation marks.
  • Use: Investigate, Filter, Assign, Escalated, Resolved. Avoid: Oops, Awesome, Please, Simply.

The labels components use, from the voice tokens:

  • content.action.commit: Save
  • content.action.cancel: Cancel
  • content.action.destroy: Delete
  • content.action.retry: Retry
  • content.action.empty-action: Change filters

See Voice and tone for the whole voice.

Accessibility and keyboard​

KeyboardWhat happensNot
undefinedArrow keys move between tabs; Tab moves into the panel.undefined

Test before you ship:

  • It is a tablist; the selected tab owns its panel. undefined

Use it in code​

npx open-ds add tabs

The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.

Tokens it reads​

Tabs reads 14 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Tabs's tokens to change Tabs alone.

Changes with theme

Dense data decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.

PartIts token and the semantic it aliasesValue
Shared
Button focus ring
Changes with theme
on focus
component.button.focus-ringcolor.border.focusvar(--button-focus-ring)Lightviolet.light.600:#4B3FD9Darkviolet.dark.600:#A9A3F6
Tabs
Indicator
Changes with theme
component.tabs.indicatorcolor.action.primaryvar(--tabs-indicator)Lightviolet.light.600:#4B3FD9Darkviolet.dark.600:#A9A3F6
Focus
on focus
component.tabs.focusborder-width.focusvar(--tabs-focus)border-width.2:2px
Canvas
Changes with theme
on focus
component.tabs.canvascolor.surface.canvasvar(--tabs-canvas)Lightslate.light.50:#F7F8FADarkslate.dark.0:#0D1117
Text
Color
Changes with theme
component.tabs.labelcolor.text.secondaryvar(--tabs-label)Lightslate.light.700:#3D4655Darkslate.dark.500:#C4CBD6
Active
Changes with theme
component.tabs.label.activecolor.text.primaryvar(--tabs-label-active)Lightslate.light.900:#161B23Darkslate.dark.900:#F7F8FA
List
Gapcomponent.tabs.list.gapspace.gap.groupvar(--tabs-list-gap)space.16:1rem
Border widthcomponent.tabs.list.border-widthborder-width.defaultvar(--tabs-list-border-width)border-width.1:1px
Border
Changes with theme
component.tabs.list.bordercolor.border.defaultvar(--tabs-list-border)Lightslate.light.200:#DDE2EADarkslate.dark.100:#262D38
Trigger
Heightcomponent.tabs.trigger.heightsize.control.defaultvar(--tabs-trigger-height)size.32:2rem
Font familycomponent.tabs.trigger.font-familytype.label.font-familyvar(--tabs-trigger-font-family)font.family.ibm-plex-sans:"IBM Plex Sans", system-ui, sans-serif
Text sizecomponent.tabs.trigger.font-sizetype.label.font-sizevar(--tabs-trigger-font-size)font.size.12:0.75rem
Weightcomponent.tabs.trigger.font-weighttype.label.font-weightvar(--tabs-trigger-font-weight)font.weight.500:500
Content
Padding, topcomponent.tabs.content.padding-topspace.gap.defaultvar(--tabs-content-padding-top)space.8:0.5rem