shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Tabs put a few views of one subject in the same spot and show one at a time: a project's overview, analytics and settings, or a snippet's preview and its code. Reach for them when people switch between views rather than read down the page.
When the sections should stack and several may be open together, use an Accordion. To pick a value that changes the content in place, such as a list or grid view, a Segment Group fits better.
Installation
Anatomy

Usage
import {
Tabs, TabsContent, TabsList, TabsTrigger,
} from "@/components/ui/tabs";Each TabsTrigger and the TabsContent it shows share a value. Set defaultValue on Tabs to the one that opens first.
<Tabs className="w-full max-w-sm" defaultValue="account">
<TabsList>
<TabsTrigger value="account">Account</TabsTrigger>
<TabsTrigger value="password">Password</TabsTrigger>
</TabsList>
<TabsContent value="account">
Change your name and the email address we write to.
</TabsContent>
<TabsContent value="password">
Change your password. Other devices are signed out when you save.
</TabsContent>
</Tabs>Accessibility
TabsList is a tablist, each trigger a tab that reports aria-selected, and each panel a tabpanel named by its tab. Only the selected tab is in the tab order, and the arrow keys move between the rest. The open panel joins the tab order only when it holds nothing focusable, so Tab goes from the list straight to the first field or link inside it. Give TabsList an aria-label when no heading says what the tabs are for, and keep a text label in every trigger.
- Tab
- When focus moves onto the tabs, focuses the active trigger. When a trigger is focused, moves focus to the active content.
- Arrow Down
- Moves focus to the next trigger in vertical orientation and activates its associated content.
- Arrow Right
- Moves focus to the next trigger in horizontal orientation and activates its associated content.
- Arrow Up
- Moves focus to the previous trigger in vertical orientation and activates its associated content.
- Arrow Left
- Moves focus to the previous trigger in horizontal orientation and activates its associated content.
- Home
- Moves focus to the first trigger and activates its associated content.
- End
- Moves focus to the last trigger and activates its associated content.
- Enter
- Selects the focused tab and shows its content, which is how a tab gets selected when
activationModeismanual. Focus stays on the tab. - Space
- Selects the focused tab and shows its content, which is how a tab gets selected when
activationModeismanual. Focus stays on the tab.
Demos
Line
Overview, Analytics and Reports in a list with variant set to line on TabsList, and no panels under them. The filled background goes and a 2px line marks the selected tab, sliding to the next one as the selection moves. Use the line style when the tabs sit on a page already full of cards, where one more filled box would crowd it.
Vertical
Account, Password and Notifications stacked in a column, with orientation set to vertical on Tabs. The demo shows only the list, and on a real page the open panel sits beside it. Up and Down move between the tabs, and Left and Right do nothing. Pick it for a settings page with more sections, or longer names, than fit on one row.
Disabled
Home is selected, and the second tab, labelled Disabled, has disabled on its TabsTrigger, so clicking it does nothing. The arrow keys skip it. Keep a disabled tab when the section exists but this account can't open it yet, and leave the tab out when it will never apply.
Icons
Preview and Code, each with an icon before its label, the familiar switch between a rendered component and its source. The icons carry aria-hidden, so a screen reader announces only the words. Use icons when they make a mode quicker to spot, and keep the text: a trigger with only an icon needs an aria-label to have a name at all.
RTL
The four tabs from the top of the page, in Arabic, inside a Direction provider set to right to left. Ark UI reads the direction from that locale and writes it on the list, every trigger and every panel, so the list runs from the right and ArrowLeft moves to the next tab. A dir attribute on Tabs alone would reach only the root element.
FAQ
How do I control the selected tab from state in React?
Hold the selected tab's value in state, pass it as value on Tabs and update it in onValueChange. The callback receives an object, so read the new tab from details.value.
Once the state is yours, anything can change it. A Next button at the foot of one panel can move to the following tab, and a page can open on a given tab by reading it from the URL.
Why is no tab selected when my Tabs first render?
Because no tab was named. Ark UI starts with nothing selected when defaultValue is missing, so no panel shows, and since only the selected trigger is in the tab order, the list can't be reached with Tab either. Set defaultValue on Tabs to the value of the tab that should open first.
How do I keep what was typed in a Tabs panel when switching tabs?
Keep the inactive panels mounted. This component turns on lazyMount and unmountOnExit, which Ark UI leaves off, so a panel is created when its tab is first selected and removed when another one is. Set both to false on Tabs and every panel stays in the DOM, hidden with the hidden attribute, with its input and scroll position intact.
Fields in a hidden panel still submit with their form, but the browser can't point at one that fails validation. Check those fields yourself and switch to the tab that holds the problem.
How do I make underline Tabs in React?
Set variant to line on TabsList, as the Line demo does, or underline, its earlier name. The filled highlight becomes a 2px line that slides to the selected tab over 200 milliseconds, and jumps instead for people who ask for reduced motion. The line is the indicator TabsList renders, in components/ui/tabs, where you can change its color or thickness.
How do I show Tabs vertically, with the list beside the panel?
Set orientation to vertical on Tabs. The root then lays out as a row, so the triggers stack down one side and the open panel fills the space beside them, and each trigger stretches to the list's width with its label at the start. The Vertical demo shows the list on its own.
The Up and Down arrow keys then move between tabs, and Left and Right do nothing.
Is the Ark UI Tabs component accessible with the keyboard?
Yes, and without any setup. Tab lands on the selected tab, the arrow keys move between tabs and skip disabled ones, and Home and End jump to the first and last.
Moving focus selects each tab as it goes. When showing a panel is slow, as with one that fetches data, set activationMode to manual on Tabs, and the arrows only move focus until Enter or Space selects.
The Accessibility section lists every key.
API Reference
Tabs
<div> data-slot="tabs"
value?string | null
The controlled selected tab value.
- Type
string | null
defaultValue?string | null
The initial selected tab value when rendered. Use when you don't need to control the selected tab value.
- Type
string | null
onValueChange?(details: ValueChangeDetails) → void
Callback to be called when the selected/active tab changes.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
activationMode?"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
- Type
"manual" | "automatic"- Default
"automatic"
composite?boolean
Whether the tab is composite.
deselectable?boolean
Whether the active tab can be deselected when clicking on it.
dir?"ltr" | "rtl"
The document's text/writing direction.
- Type
"ltr" | "rtl"- Default
"ltr"
hideMode?"display-none" | "activity"
How to hide content when mounted but not present.
- display-none: HTML hidden attribute. Effects stay alive.
- activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.
- Type
"display-none" | "activity"- Default
"display-none"
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the tabs. Useful for composition.
- Type
{ root?: string; trigger?: (value: string) → string; list?: string; content?: (value: string) → string; indicator?: string }
lazyMount?boolean
Whether to enable lazy mounting. Ark default: false.
- Default
true
loopFocus?boolean
Whether the keyboard navigation will loop from last tab to first, and vice versa.
- Default
true
navigate?((details: NavigateDetails) → void) | null
Function to navigate to the selected tab when clicking on it. Useful if tab triggers are anchor elements.
- Type
((details: NavigateDetails) → void) | null- Parameters
(details– { value: string; node: HTMLAnchorElement; href: string }- Returns
void) | null
onFocusChange?(details: FocusChangeDetails) → void
Callback to be called when the focused tab changes.
- Type
(details: FocusChangeDetails) → void- Parameters
details– { focusedValue: string }- Returns
void
orientation?"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.
- Type
"horizontal" | "vertical"- Default
"horizontal"
translations?object
Specifies the localized strings that identifies the accessibility elements and their states.
- Type
{ listLabel?: string }
unmountOnExit?boolean
Whether to unmount on exit. Ark default: false.
- Default
true
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-focus?string
Present when focused.
data-orientation"horizontal" | "vertical"
The orientation of the tabs.
- Type
"horizontal" | "vertical"
TabsList
data-slot="tabs-list"
variant?"default" | "line" | "underline"
The visual style. underline is the earlier name of line and still
works.
- Type
"default" | "line" | "underline"- Default
"default"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-focus?string
Present when focused.
data-orientation"horizontal" | "vertical"
The orientation of the list.
- Type
"horizontal" | "vertical"
data-variant?stringTabsTrigger
data-slot="tabs-trigger"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-disabled?string
Present when disabled.
data-focus?string
Present when focused.
data-orientation"horizontal" | "vertical"
The orientation of the trigger.
- Type
"horizontal" | "vertical"
data-ownedbystring
Id of the list part.
data-selected?string
Present when selected.
data-ssr?string
Present when not rendered in the browser. Useful for ssr styling.
data-valuestring
The value of the item.
TabsContent
data-slot="tabs-content"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-orientation"horizontal" | "vertical"
The orientation of the content.
- Type
"horizontal" | "vertical"
data-ownedbystring
Id of the list part.
data-selected?string
Present when selected.
TabsIndicator
data-slot="tab-indicator"
data-orientation"horizontal" | "vertical"
The orientation of the indicator.
- Type
"horizontal" | "vertical"
--heightstring
The height of the element.
--leftstring
The left position value.
--topstring
The top position value.
--transition-propertystring
The transition property value for the Indicator.
--widthstring
The width of the element.
TabsRootProvider
<div> data-slot="tabs"
valueUseTabsReturn
What useTabs() returns: the state and API, made outside the component to control it.
hideMode?"display-none" | "activity"
How to hide content when mounted but not present.
- display-none: HTML hidden attribute. Effects stay alive.
- activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.
- Type
"display-none" | "activity"- Default
"display-none"
lazyMount?boolean
Whether to enable lazy mounting. Ark default: false.
- Default
true
unmountOnExit?boolean
Whether to unmount on exit. Ark default: false.
- Default
true
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-focus?string
Present when focused is true.
data-orientation"horizontal" | "vertical"
Mirrors the orientation prop.
- Type
"horizontal" | "vertical"
--heightstring
The measured height, for animating open and closed.
--leftstring--topstring--widthstring
The measured width, for animating open and closed.
useTabs
value?string | null
The controlled selected tab value.
- Type
string | null
defaultValue?string | null
The initial selected tab value when rendered. Use when you don't need to control the selected tab value.
- Type
string | null
onValueChange?(details: ValueChangeDetails) → void
Callback to be called when the selected/active tab changes.
- Type
(details: ValueChangeDetails) → void- Parameters
details– { value: string }- Returns
void
activationMode?"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
- Type
"manual" | "automatic"- Default
"automatic"
composite?boolean
Whether the tab is composite.
deselectable?boolean
Whether the active tab can be deselected when clicking on it.
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the tabs. Useful for composition.
- Type
{ root?: string; trigger?: (value: string) → string; list?: string; content?: (value: string) → string; indicator?: string }
loopFocus?boolean
Whether the keyboard navigation will loop from last tab to first, and vice versa.
- Default
true
navigate?((details: NavigateDetails) → void) | null
Function to navigate to the selected tab when clicking on it. Useful if tab triggers are anchor elements.
- Type
((details: NavigateDetails) → void) | null- Parameters
(details– { value: string; node: HTMLAnchorElement; href: string }- Returns
void) | null
onFocusChange?(details: FocusChangeDetails) → void
Callback to be called when the focused tab changes.
- Type
(details: FocusChangeDetails) → void- Parameters
details– { focusedValue: string }- Returns
void
orientation?"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.
- Type
"horizontal" | "vertical"- Default
"horizontal"
translations?object
Specifies the localized strings that identifies the accessibility elements and their states.
- Type
{ listLabel?: string }
TabsContext
clearValueVoidFunction
Clears the value of the tabs.
focusVoidFunction
Set focus on the selected tab trigger.
focusedValuestring | null
The value of the tab that is currently focused.
- Type
string | null
getTriggerState(props: TriggerProps) → TriggerState
Returns the state of the trigger with the given props.
- Type
(props: TriggerProps) → TriggerState- Parameters
props– { value: string; disabled?: boolean }- Returns
TriggerState
selectNext(fromValue?: string) → void
Selects the next tab.
- Parameters
fromValue?– string- Returns
void
selectPrev(fromValue?: string) → void
Selects the previous tab.
- Parameters
fromValue?– string- Returns
void
setIndicatorRect(value: string) → void
Sets the indicator rect to the tab with the given value.
- Parameters
value– string- Returns
void
setValue(value: string) → void
Sets the value of the tabs.
- Parameters
value– string- Returns
void
syncTabIndexVoidFunction
Synchronizes the tab index of the content element. Useful when rendering tabs within a select or combobox
valuestring | null
The current value of the tabs.
- Type
string | null











