Usage
import { Tabs } from "@chakra-ui/react"<Tabs.Root>
<Tabs.List>
<Tabs.Trigger />
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content />
</Tabs.Root>Examples
Variants
Use the variant prop to change the visual style of the tabs.
Lazy Mounted
Use the lazyMount and/or unmountOnExit prop to only render the tab content
when it is active. This can be useful for performance optimization.
Indicator
Render the Tabs.Indicator component to display a visual indicator of the
active tab.
Custom Indicator
Customize the indicator appearance using CSS variables like
--tabs-indicator-bg and --tabs-indicator-shadow.
Links
Pass the asChild to the Tabs.Trigger component to render a link as a tab.
When a tab is clicked, the link will be navigated to.
When using custom router links, you need to set the navigate prop on the
Tabs.Root component.
"use client"
import { Tabs } from "@chakra-ui/react"
import { useNavigate } from "react-router-dom"
const Demo = () => {
const navigate = useNavigate()
return (
<Tabs.Root navigate={({ value, node }) => navigate(`/${value}`)}>
{/* ... */}
</Tabs.Root>
)
}Fitted
Use the fitted prop to make the tabs fit the width of the container.
Controlled
Use the value and onValueChange prop to control the active tab.
Store
An alternative way to control the tabs is to use the RootProvider component
and the useTabs store hook.
This way you can access the tabs state and methods from outside the tabs.
selected: membersDisabled Tab
Set the disabled prop on the Tabs.Trigger component to disable a tab.
Manual activation
By default, the tabs are selected when the arrow keys are pressed. Disable this
behavior by setting the activationBehavior prop to manual.
In this mode, the tabs will only be selected when clicked or the enter key is pressed.
Dynamic
Here's an example of how to dynamically add and remove tabs.
Tab Content 1
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
Tab Content 2
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
Tab Content 3
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
Tab Content 4
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
Responsive Orientation
Responsive values are not supported for the orientation prop because it
affects keyboard navigation and aria-orientation behavior, not just styling.
The orientation changes how arrow keys work (horizontal uses left/right,
vertical uses up/down).
To achieve responsive orientation, use the useBreakpointValue hook to change
the orientation based on the screen size.
Animation
Use the _open and _close conditional props to animate the tabs.
Props
Root
| Prop | Default | Type |
|---|---|---|
activationMode | 'automatic' | 'manual' | 'automatic'The activation mode of the tabs. Can be `manual` or `automatic` - `manual`: Tabs are activated when clicked or press `enter` key. - `automatic`: Tabs are activated when receiving focus |
lazyMount | false | booleanWhether to enable lazy mounting |
loopFocus | true | booleanWhether the keyboard navigation will loop from last tab to first, and vice versa. |
orientation | 'horizontal' | 'horizontal' | 'vertical'The orientation of the tabs. Can be `horizontal` or `vertical` - `horizontal`: only left and right arrow key navigation will work. - `vertical`: only up and down arrow key navigation will work. |
unmountOnExit | false | booleanWhether to unmount on exit. |
colorPalette | gray | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'The color palette of the component |
size | md | 'sm' | 'md' | 'lg'The size of the component |
variant | line | 'line' | 'subtle' | 'enclosed' | 'outline' | 'plain'The variant of the component |
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
unstyled | booleanWhether to remove the component's style. | |
composite | booleanWhether the tab is composite | |
defaultValue | stringThe initial selected tab value when rendered. Use when you don't need to control the selected tab value. | |
deselectable | booleanWhether the active tab can be deselected when clicking on it. | |
id | stringThe unique identifier of the machine. | |
ids | Partial<{ root: string; trigger: string; list: string; content: string; indicator: string }>The ids of the elements in the tabs. Useful for composition. | |
navigate | (details: NavigateDetails) => voidFunction to navigate to the selected tab when clicking on it. Useful if tab triggers are anchor elements. | |
onFocusChange | (details: FocusChangeDetails) => voidCallback to be called when the focused tab changes | |
onValueChange | (details: ValueChangeDetails) => voidCallback to be called when the selected/active tab changes | |
translations | IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states | |
value | stringThe controlled selected tab value | |
fitted | 'true' | 'false'The fitted of the component | |
justify | 'start' | 'center' | 'end'The justify of the component |
Trigger
| Prop | Default | Type |
|---|---|---|
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
Content
| Prop | Default | Type |
|---|---|---|
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
Explorer
Explore the Tabs component parts interactively. Click on parts in the sidebar
to highlight them in the preview.
Component Anatomy
Hover to highlight, click to select parts
root
trigger
list
content
contentGroup
indicator