Molecules · Tabs
Tabs
Sections of one view, with only one visible at a time. The active tab has the selected look the NavRail and the Sidebar share: a neutral surface with a 2px signal underline.
- Best for
- Switching between equally important sections of one view.
- Not for
- Steps in a sequence: use Stepper. Moving between pages: use links (Navbar, Sidebar).
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Default
Electric carbine replica.
Code
tsx
<div className="max-w-sm w-full"> <Tabs defaultValue="replica"> <TabsList aria-label="Kit sections"> <TabsTrigger value="replica">Replica</TabsTrigger> <TabsTrigger value="optics">Optics</TabsTrigger> <TabsTrigger value="parts">Parts</TabsTrigger> </TabsList> <TabsContent value="replica">Electric carbine replica.</TabsContent> <TabsContent value="optics">Tube sight and holo sight.</TabsContent> <TabsContent value="parts">Magazines, a battery and a charger.</TabsContent> </Tabs></div>More tabs than fit: swipe on touch, chevrons with a mouse, arrow keys always
Overview for the field day project.
Code
tsx
<div className="max-w-sm w-full"> <Tabs defaultValue="overview"> <TabsList aria-label="Project sections"> {['Overview', 'Activity', 'Members', 'Files', 'Reports', 'Settings', 'Billing', 'Integrations'].map((t) => ( <TabsTrigger key={t} value={t.toLowerCase()}> {t} </TabsTrigger> ))} </TabsList> {['Overview', 'Activity', 'Members', 'Files', 'Reports', 'Settings', 'Billing', 'Integrations'].map((t) => ( <TabsContent key={t} value={t.toLowerCase()}> {t} for the field day project. </TabsContent> ))} </Tabs></div>With a disabled tab
Electric carbine replica.
Code
tsx
<div className="max-w-sm w-full"> <Tabs defaultValue="replica"> <TabsList aria-label="Kit sections"> <TabsTrigger value="replica">Replica</TabsTrigger> <TabsTrigger value="optics">Optics</TabsTrigger> <TabsTrigger value="parts" disabled> Parts </TabsTrigger> </TabsList> <TabsContent value="replica">Electric carbine replica.</TabsContent> <TabsContent value="optics">Tube sight and holo sight.</TabsContent> <TabsContent value="parts">Magazines, a battery and a charger.</TabsContent> </Tabs></div>Line, with icons and counts
Twelve orders waiting to be packed.
Code
tsx
<div className="max-w-md w-full"> <Tabs defaultValue="open" variant="line"> <TabsList aria-label="Orders"> <TabsTrigger value="open" icon={<Inbox />} count={12}> Open </TabsTrigger> <TabsTrigger value="packed" icon={<Package />} count={4}> Packed </TabsTrigger> <TabsTrigger value="archived" icon={<Archive />} count={0}> Archived </TabsTrigger> </TabsList> <TabsContent value="open">Twelve orders waiting to be packed.</TabsContent> <TabsContent value="packed">Four orders packed, waiting for the courier.</TabsContent> <TabsContent value="archived">No archived orders yet.</TabsContent> </Tabs></div>Vertical, fill: the underline moves to the inline-end edge
Callsign, squad and home field.
Code
tsx
<div className="max-w-md w-full"> <Tabs defaultValue="profile" orientation="vertical"> <TabsList aria-label="Account settings"> <TabsTrigger value="profile" icon={<User />}> Profile </TabsTrigger> <TabsTrigger value="security" icon={<Shield />}> Security </TabsTrigger> </TabsList> <TabsContent value="profile">Callsign, squad and home field.</TabsContent> <TabsContent value="security">Password and signed-in devices.</TabsContent> </Tabs></div>Vertical, line
Callsign, squad and home field.
Code
tsx
<div className="max-w-md w-full"> <Tabs defaultValue="profile" orientation="vertical" variant="line"> <TabsList aria-label="Settings"> <TabsTrigger value="profile" icon={<User />}> Profile </TabsTrigger> <TabsTrigger value="security" icon={<Shield />}> Security </TabsTrigger> </TabsList> <TabsContent value="profile">Callsign, squad and home field.</TabsContent> <TabsContent value="security">Password and signed-in devices.</TabsContent> </Tabs></div>Controlled: the page keeps track of which tab is open
Electric carbine replica.
Code
tsx
function ControlledExample() { const [value, setValue] = useState('replica') return ( <div className="max-w-sm w-full"> <div className="flex gap-2 mb-4"> <Button size="sm" variant="secondary" onClick={() => setValue('replica')}> Show replica </Button> <Button size="sm" variant="secondary" onClick={() => setValue('optics')}> Show optics </Button> </div> <Tabs value={value} onValueChange={setValue}> <TabsList aria-label="Kit sections"> <TabsTrigger value="replica">Replica</TabsTrigger> <TabsTrigger value="optics">Optics</TabsTrigger> </TabsList> <TabsContent value="replica">Electric carbine replica.</TabsContent> <TabsContent value="optics">Tube sight and holo sight.</TabsContent> </Tabs> </div> )}<ControlledExample />Anatomy
| Part | What it is |
|---|---|
| Tabs | The root. Holds which tab is active, whether the page controls that or the component does. |
| TabsList | The tablist, the row of tabs. It needs an aria-label (a name read out by screen readers). When the tabs don't fit, it scrolls sideways inside itself with no scrollbar: the edge that still hides tabs fades out, a swipe snaps the leftmost tab into place on touch, and with a mouse a chevron button sits over each fade. |
| TabsTrigger | A single tab. Fill variant: the active tab sits on the neutral surface.selected, with primary text in semibold and a 2px (pixel) signal underline; orange is only that line, never a fill. Hovering an inactive tab adds a 12% signal tint. Line variant: the active tab is primary text over the 2px signal bar alone. In both, the line moves to the inline end (the side text runs towards) when the tabs are vertical, and slides to the new tab when the active one changes. |
| Icon | Optional, before the label. aria-hidden, so screen readers skip it. |
| Count | Optional, after the label. You see it as a number, and screen readers read it as part of the name: Open (12). |
| TabsContent | A tabpanel, the area a tab shows. It's labelled by its tab and can take focus, so a keyboard user can reach panels that hold only text. |
Props
- value (Root)string
- The active tab, when the page controls it.
- variant'fill' | 'line'Default 'fill'
- How the active tab is shown (Root). 'fill' puts it on the neutral selected surface with a signal underline; 'line' keeps only the underline, for a row inside a panel that already has lots of fills.
- defaultValuestring
- The tab that starts active, when the component manages it (Root).
- onValueChange(value: string) => void
- Called when the active tab changes (Root).
- orientation'horizontal' | 'vertical'Default 'horizontal'
- Which arrow keys move between tabs (Root). Vertical also puts the list beside the panels.
- activationMode'automatic' | 'manual'Default 'automatic'
- 'manual' waits for Enter or Space before switching, for panels that are slow to draw (Root).
- value (Trigger)string
- This tab's own value.
- disabledbooleanDefault false
- Turns off one tab (Trigger).
- icon (Trigger)ReactNode
- A small symbol before the label, hidden from screen readers (aria-hidden).
- count (Trigger)number
- A number after the label, included in the name screen readers announce.
- classNamestring
- Merged with the root classes. If two Tailwind utilities clash, the later one wins. Available on every part.
- refRef<HTMLElement>
- Passed through to the underlying page element. Available on every part.
Keyboard
| Keys | Result |
|---|---|
| Tab | Moves into the tab row, onto the active tab. Pressing Tab again moves into the panel. |
| ArrowLeftArrowRight | Previous or next tab. It wraps round at the ends and skips turned-off tabs. |
| ArrowUpArrowDown | The same, when orientation is vertical. |
| HomeEnd | First or last tab. |
Do and don't
Do
- Keep tab labels to one or two words.
- Use tabs for equals: sections a person would move between freely.
- Give the tab row an aria-label that names the whole set.
- Use the line variant inside a card or settings panel, and the fill variant at the top of a view.
- Use a count for something a person would act on, like open orders or unread reports.
Don't
- Don't use tabs for steps in a sequence. That's what Stepper is for.
- Don't put a second row of tabs inside a panel.
- Don't mix fill and line tabs on one page.
- Don't give every tab an icon just because one has one. Icons go on all of them or none.
- Don't use tabs to move between pages. A tab changes what's shown, not where you are.