Tabs
Switch between different views
Source
LLM docs
Docs
Package
Usage
Controlled Tabs
To control the Tabs state, use value and onChange props:
Uncontrolled Tabs
If you do not need to subscribe to Tabs state changes, use defaultValue:
Change colors
To change the colors of all tabs, set color on the Tabs component; to change the color of an individual tab,
set color on Tabs.Tab.
Tabs position
To display a tab on the opposite side, set margin-left: auto with the ml="auto" prop or with className:
Inverted tabs
To make tabs inverted, place Tabs.Panel components before Tabs.List and add the inverted prop to the Tabs component:
Vertical tabs placement
To change the placement of Tabs.List in vertical orientation, set the placement prop:
Custom variants
Example of custom variant with FloatingIndicator:
Disabled tabs
Set the disabled prop on the Tabs.Tab component to disable a tab.
Disabled tabs cannot be activated with the mouse or keyboard, and they will be skipped when the user navigates with arrow keys:
Activation mode
By default, tabs are activated when the user presses arrow keys or Home/End keys.
To disable that, set activateTabWithKeyboard={false} on the Tabs component:
Tab deactivation
By default, the active tab cannot be deactivated. To allow that, set allowTabDeactivation on the Tabs component:
Unmount inactive tabs
By default, inactive Tabs.Panel will stay mounted; to unmount inactive tabs, set keepMounted={false} on Tabs.
This is useful when you want to render components that impact performance inside Tabs.Panel. Note that
components that are rendered inside Tabs.Panel will reset their state on each mount (tab change).
Get tab control ref
Tab as a link
You can render Tabs.Tab as an a element by using the renderRoot prop. This gives you
native link behavior: right-click to open in a new tab, middle-click, and href for
crawlers and accessibility.
You can also use the component prop to render tabs as links:
Tab as a link with Next.js
Use the renderRoot prop to render Tabs.Tab as a Next.js Link component. The renderRoot prop
is required instead of component because Next.js Link is a generic component:
Tab as a link with React Router
Use the renderRoot prop to render Tabs.Tab as a React Router NavLink or Link component:
Usage with react-router
Usage with Next.js Pages Router
Usage with Next.js App Router
In the App Router, get the current tab value from the pathname with the usePathname
hook and change tabs with the router returned by useRouter. Both hooks are imported
from next/navigation. Note that components that use these hooks must be
Client Components
(add the 'use client' directive at the top of the file).
Styles API
Tabs supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Example of Styles API usage to customize tab styles:
Example with Scroller component
Use Scroller component to make the tabs list scrollable when there are too many tabs to fit in the available space:
Accessibility
The Tabs component follows WAI-ARIA recommendations on accessibility.
Tabs as links
When Tabs.Tab is rendered as a link (<a> tag), the role="tab" attribute overrides
the implicit link role. Screen readers will announce the element as a "tab", not a "link".
This is the expected behavior per the WAI-ARIA specification.
When using tabs as navigation links without Tabs.Panel components, the aria-controls attribute
on each tab references a panel element that does not exist in the DOM. This is a minor
accessibility consideration – most screen readers handle this gracefully.
If you use Tabs.Tab without text content, for example, only with an icon, then set aria-label
or use the VisuallyHidden component:
To set the tabs list label, set aria-label on the Tabs.List component; it will be announced by screen reader: