Skip to main content
U.S. Flag

An official website of the United States government

Tabs

Tabs are a secondary navigation pattern, allowing a user to view only the content they're interested in. They build upon a real world metaphor, and the selected state simulates a folder being physically in front of others in the group.

Examples

Loading

Code

React

<Tabs> component

Tabs is a container component that manages the state of your tabs for you. In most cases, you'll want to use this component rather than the presentational components (Tab, TabPanel) on their own.

React Properties Documentation
NameTypeDefaultDescription
childrenrequiredReact.ReactNode

Must only contain TabPanel components

defaultSelectedIdstring

Sets the initial selected TabPanel state. If this isn't set, the first TabPanel will be selected.

onChange(selectedId: string, prevSelectedId: string) => any

A callback function that's invoked when the selected tab is changed. (selectedId, prevSelectedId) => void

tablistClassNamestring

Additional classes to be added to the component wrapping the tabs

<TabPanel> component

A TabPanel is a presentational component which accepts a tab's content as its children.

React Properties Documentation
NameTypeDefaultDescription
childrenrequiredReact.ReactNode
classNamestring

Additional classes to be added to the root element.

idrequiredstring

A unique id, to be used on the rendered panel element.

selectedbooleanfalse
disabledboolean
tabstring

The associated tab's label. Only applicable when the panel is a child of Tabs.

tabClassNamestring

Additional classes for the associated tab. Only applicable when the panel is a child of Tabs.

tabHrefstring

The associated tab's href. Only applicable when the panel is a child of Tabs.

tabIdstring

The id of the associated Tab. Used for the aria-labelledby attribute.

Styles

The following Sass variables can be overridden to customize Tab components:

Sass variables for tabs
VariableDefault Core Theme Value
$tabs__border-color$color-border
$tabs__background-color$color-white
$tabs__color$color-base
$tabs-selected__background-color$color-primary
$tabs-selected__border-color$color-white
$tabs-selected__color$color-primary
$tabs-selected__border-color--active$color-primary
$tabs__color--hover$color-primary
$tabs__color--active$color-primary-darker
$tabs__background-color--disabled$color-border
$tabs__border-color--disabled$color-border
$tabs__color--disabled$color-gray-dark

Guidance

When to use

  • If you have sub-sections of a page, and there's the need to only show one sub-section at a time.

When to consider alternatives

  • If you have more than four tabs. Consider using a different pattern if your content requires being split into more than four panels.
  • If the panel contents can be displayed at once. This will improve the scanability of your page's content and it's more likely the user will be able to find what they're looking for. Typography, including clear section headers, should be enough to allow the user to navigate the page.

Usage

  • Avoid overflowing tabs to new lines. If the tabs can't fit on one row on small screens, consider using utility classes to apply additional responsive styles or use a different pattern.
  • Tab labels should be descriptive of their content and set the user's expectations.
  • Tab labels should be short — aim for no more than two words.

Accessibility

  • Use an anchor link (a) to create the tabs. This allows you to link directly to a tab, and allows you to progressively enhance the page, retaining default browser behavior like opening links in a new window. Note: You'll need to implement the logic for selecting the correct tab based on the current URL.
  • Ensure the HTML markup includes the proper ARIA attributes:
    • For tabs: role, aria-selected, aria-controls
    • For the tabs list parent: role, aria-label
    • For a tab panel: role, aria-labelledby

Learn more

Component maturity

For more information about how we tested and validated our work for each checklist item, read our component maturity documentation.

Accessibility

  • Color

    Meets AA color contrast standards for accessibility and color blindness.
    Complete
  • Forced Colors Mode (FCM)

    While using FCM the components text is legible and improves readability.
    Complete
  • WCAG 2.1 Level AA Conformance

    All Axe checks for WCAG AA compliance have passed.
    Complete
  • Screen readers

    VoiceOver, NVDA, and JAWS screen readers provide concise communication and interaction.
    Complete
  • Keyboard navigation

    Component is fully navigable with a keyboard.
    Complete

Code

  • Storybook

    Component has stories to cover all defined props.
    Complete
  • Responsive

    Component designed to work in all responsive breakpoints.
    Incomplete
  • Spanish translations

    Includes Spanish translations for default text content.
    Not applicable

Tokens

  • Code

    Tokens implemented in code.
    Complete
  • Design

    Tokens implemented in the Sketch.
    Complete