Tabs
Switches between views of the same subject without leaving the page.
When to use
- Two to five views of the same subject, shown one at a time: a source's overview, records, and settings.
- Content that doesn't need to be compared side by side.
When not to use
- Steps of a flow users move through in order: use one page per step, or a form with Field groups.
- Changing a filter or a mode on the same content: use Toggle Group.
- Moving between pages of the app: use Navigation Menu or Sidebar.
- Splitting one form across views: users miss required fields in tabs they never opened. Keep the form on one page.
Install
npx shadcn@latest add @clinia/tabsPatient overview and key metrics.
Anatomy
Montreal clinic: 3 sources, synced today.
- 1List
data-slot="tabs-list"bg-muted · rounded-lg - 2Active tab
[data-slot=tabs-trigger][data-active]bg-background · text-foreground - 3Tab
[data-slot=tabs-trigger]:not([data-active])text-sm · text-muted-foreground - 4Panel
data-slot="tabs-content"text-sm
Clinia rules
defaultis a segmented group onbg-muted: the active tab lifts tobg-backgroundwithtext-foreground, and the others staytext-muted-foreground.lineunderlines the active tab inforeground, with no background. Use it for page-level tabs.- Labels are one or two words, sentence case, and name the view:
Overview,Records,Settings. Keep them on one line. - Tabs switch views. They never save, submit, or move a flow forward.
Do and don't
States
default
line
disabled tab
vertical
focus
Focus cells apply the component's focus-visible classes statically. Toggle the site theme to review both themes.
Accessibility
Built in
- A trigger's border is transparent by default, so its focus-visible state pairs the Trust ring with an extra solid
outline-ringto stay visible. - The list is one tab stop. Arrow keys move between tabs and loop at the ends.
- A tab shows its panel on Enter or Space, not on focus, unless
activateOnFocusis set onTabsList.
Your responsibility
- Give
TabsListanaria-labelwhen no visible heading names the set of views. - Keep each label unique. Two tabs named
Detailscan't be told apart when read aloud.
How to test
- Press Tab: focus lands on the active tab and the ring appears. Press Tab again: focus moves into the panel, not to the next tab.
- Press Arrow Right and Arrow Left: focus moves between tabs and wraps at the ends.
- Press Enter or Space on a focused tab: its panel shows.
- With a screen reader, a tab is announced as its label, a tab, its position in the list, and selected when active.
API
TabsList
| Prop | Values | Default | Description |
|---|---|---|---|
| variant | defaultline | default |
|
All other props come from Base UI Tabs.