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
<script setup lang="ts">
import {
Tabs, TabsContent, TabsList, TabsTrigger,
} from "@/components/ui/tabs";
</script>
Each TabsTrigger and the TabsContent it shows share a value. Set defaultValue on Tabs to the one that opens first.
<template>
<Tabs class="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>
</template>
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
- From outside the list, moves focus to the selected tab. From a tab, moves focus to the open panel, or to the first field or link inside it.
- Arrow Right
- In a horizontal list, moves focus to the next tab and selects it, wrapping from the last to the first. A disabled tab takes focus but isn't selected. In right-to-left text it goes the other way.
- Arrow Left
- In a horizontal list, moves focus to the previous tab and selects it, wrapping from the first to the last. In right-to-left text it goes the other way.
- Arrow Down
- In a vertical list, moves focus to the next tab and selects it.
- Arrow Up
- In a vertical list, moves focus to the previous tab and selects it.
- Home
- Moves focus to the first tab and selects it.
- End
- Moves focus to the last tab and selects it.
- Enter
- Selects the focused tab, which is how a tab gets selected when
activationModeismanualonTabs. - Space
- Selects the focused tab, which is how a tab gets selected when
activationModeismanualonTabs.
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, fading from tab to tab 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 still stop on it but don't select 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, which writes dir on an element around them. UI SDK reads the arrow keys' direction from the nearest dir, so the list runs from the right and ArrowLeft moves to the next tab. Setting dir to rtl on Tabs alone would do the same.
FAQ
How do I control the selected tab from state in Vue?
Hold the selected tab's value in a ref and bind it with v-model on Tabs, which reads and writes the value of the selected TabsTrigger.
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?
UI SDK never leaves Tabs empty: when defaultValue is missing it selects the first tab that isn't disabled, from the first render, and clicking the selected tab again keeps it selected. If one tab shows up empty, check that its TabsContent has the same value as its TabsTrigger. Set defaultValue on Tabs to open on another tab.
How do I keep what was typed in a Tabs panel when switching tabs?
Add keepMounted to each TabsContent whose state should survive. UI SDK removes an inactive panel by default, and with the prop the 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 Vue?
Set variant to line on TabsList, as the Line demo does. The list drops its muted background, and each trigger draws a 2px bar under itself that shows only while it is selected, so the line fades from tab to tab instead of sliding. The bar is an after pseudo-element in TabsTrigger, 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 UI SDK Tabs component accessible with the keyboard?
Yes, and without any setup. Tab lands on the selected tab, the arrow keys move between tabs, 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?T | null
The selected tab's value. Pass it to control the tabs. null selects nothing. Two-way with v-model.
- Type
T | null
defaultValue?T | null
The tab selected at first, when uncontrolled. Defaults to the first enabled tab, which never calls onValueChange.
- Type
T | null
onValueChange?object
Runs when the selection wants to change. details.reason says why, and
details.cancel() stops it. The value is null only when your code
selects nothing.
- Type
{ bivarianceHack: (value: string | null, details: TabsChangeDetails) → void }
activation?"automatic" | "manual"
"automatic" selects a tab as soon as arrow keys focus it. "manual" waits for Enter or Space. UI SDK's default: automatic.
- Type
"automatic" | "manual"- Default
list.activation
controller?{ getValue: () → T | null; setValue: (value: T | null, options?: TabsChangeOptions) → boolean; select: (value: T, options?: TabsChangeOptions) → boolean; focus: () → void; }
Selects tabs from anywhere. Create one with createTabsController().
- Type
{ getValue: () → T | null; setValue: (value: T | null, options?: TabsChangeOptions) → boolean; select: (value: T, options?: TabsChangeOptions) → boolean; focus: () → void; }
debug?boolean
Logs every state change with its reason to the console, in development builds.
hiddenUntilFound?boolean
Keeps hidden panels in the page as hidden="until-found", so the browser's find in page can match their text and select their tab. Implies keepMounted.
- Default
false
loop?boolean
Whether arrow keys wrap from the last tab to the first. UI SDK's default: true.
- Default
list.loop
orientation?TabsOrientation
Which arrow keys move between tabs: left and right, or up and down.
- Default
"horizontal"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-activation-direction"none" | "left" | "right" | "up" | "down"
Which way the last selection moved on screen. Use it to slide panels in from the right side.
- Type
"none" | "left" | "right" | "up" | "down"
data-orientation"horizontal" | "vertical"
Which arrow keys move between tabs.
- Type
"horizontal" | "vertical"
TabsList
<div> data-slot="tabs-list"
activateOnFocus?boolean
Select a tab as soon as the arrow keys focus it; otherwise Enter or
Space selects it. Sets the tabs' activation.
- Default
true
loopFocus?boolean
Wrap the arrow keys from the last tab to the first. Sets the tabs' loop.
variant?"default" | "line"
The visual style.
- Type
"default" | "line"- Default
"default"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-activation-direction"none" | "left" | "right" | "up" | "down"
Which way the last selection moved on screen. Use it to slide panels in from the right side.
- Type
"none" | "left" | "right" | "up" | "down"
data-has-icons?string
Present while any tab inside holds an icon part, so items without one can line up.
data-orientation"horizontal" | "vertical"
Which arrow keys move between tabs.
- Type
"horizontal" | "vertical"
data-variant?string
Mirrors variant.
TabsTrigger
<button> data-slot="tabs-tab"
valuestring
Identifies the tab and pairs it with the panel of the same value.
disabled?boolean
Keeps the tab focusable but stops it from being selected, as the tabs pattern asks.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-activation-direction"none" | "left" | "right" | "up" | "down"
Which way the last selection moved on screen. Use it to slide panels in from the right side.
- Type
"none" | "left" | "right" | "up" | "down"
data-disabled?string
Present when the tab can't be selected.
data-has-icon?string
Present on a tab while it holds an icon part.
data-orientation"horizontal" | "vertical"
Which arrow keys move between tabs.
- Type
"horizontal" | "vertical"
data-selected?string
Present on the selected tab and its panel.
TabsContent
<div> data-slot="tabs-panel"
valuestring
The value of the tab this panel belongs to.
hiddenUntilFound?boolean
Whether the panel stays findable with hidden="until-found" while its tab isn't selected. Overrides the tabs'.
keepMounted?boolean
Whether the panel stays in the page, hidden, while its tab isn't selected.
- Default
false
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-activation-direction"none" | "left" | "right" | "up" | "down"
Which way the last selection moved on screen. Use it to slide panels in from the right side.
- Type
"none" | "left" | "right" | "up" | "down"
data-ending-style?string
Present while the previous panel animates out. Style the state you animate to.
data-orientation"horizontal" | "vertical"
Which arrow keys move between tabs.
- Type
"horizontal" | "vertical"
data-selected?string
Present on the selected tab and its panel.
data-starting-style?string
Present for a panel's first frame. Style the state you animate from.











