Navigation
Tabs
Switches between related panels of content in the same place.
Installation
npx sinaui add tabsCopy the src/lib/ui/tabs/ folder and tokens.css. No dependencies.
Examples
Basic
Click a tab and the indicator slides; use the arrow keys and it snaps. Disabled tabs are skipped.
x² + 10x = 39.<script lang="ts">
import * as Tabs from '#lib/ui/tabs/index.js';
let scholar = $state('ibn-sina');
</script>
<Tabs.Root bind:value={scholar}>
<Tabs.List label="Scholars">
<Tabs.Tab value="ibn-sina">Ibn Sina</Tabs.Tab>
<Tabs.Tab value="khwarizmi">Al-Khwarizmi</Tabs.Tab>
<Tabs.Tab value="biruni" disabled>Al-Biruni</Tabs.Tab>
<Tabs.Tab value="fihri">Fatima al-Fihri</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="ibn-sina">
The Canon of Medicine, taught in Europe's medical schools for centuries.
</Tabs.Panel>
<Tabs.Panel value="khwarizmi">
Al-Jabr gave algebra its name, solving problems like <code>x² + 10x = 39</code>.
</Tabs.Panel>
<Tabs.Panel value="biruni">Measured the radius of the Earth from a mountaintop.</Tabs.Panel>
<Tabs.Panel value="fihri">Founded al-Qarawiyyin in Fez in 859, still teaching today.</Tabs.Panel>
</Tabs.Root>Vertical, manual activation
Arrows move focus without switching; Enter or Space opens the tab. Use manual activation when panels are slow to render.
<script lang="ts">
import * as Tabs from '#lib/ui/tabs/index.js';
</script>
<!-- No value: the first enabled tab is selected, already in the server-rendered HTML. -->
<Tabs.Root orientation="vertical" activation="manual">
<Tabs.List label="Ibn al-Haytham's Book of Optics">
<Tabs.Tab value="light">Light</Tabs.Tab>
<Tabs.Tab value="vision">Vision</Tabs.Tab>
<Tabs.Tab value="camera">Camera obscura</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="light">
Light travels in straight lines, shown by experiment rather than argument alone.
</Tabs.Panel>
<Tabs.Panel value="vision">
We see because light enters the eye, not because the eye sends out rays.
</Tabs.Panel>
<Tabs.Panel value="camera">
A dark room with a small hole projects an inverted image of the world outside.
</Tabs.Panel>
</Tabs.Root>Compact
The small size: smaller text and a tighter gap, for small panels such as dashboard cards.
<script lang="ts">
import * as Tabs from '#lib/ui/tabs/index.js';
let by = $state('city');
</script>
<Tabs.Root bind:value={by} size="sm">
<Tabs.List label="Loans by">
<Tabs.Tab value="city">City</Tabs.Tab>
<Tabs.Tab value="subject">Subject</Tabs.Tab>
<Tabs.Tab value="language">Language</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="city">Baghdad 412, Córdoba 287, Cairo 196.</Tabs.Panel>
<Tabs.Panel value="subject">Medicine 341, astronomy 302, mathematics 252.</Tabs.Panel>
<Tabs.Panel value="language">Arabic 701, Persian 118, Greek 76.</Tabs.Panel>
</Tabs.Root>Fit to the chosen panel
By default the area keeps the tallest panel's height, so nothing below moves when tabs switch. With fit it takes the chosen panel's height instead: use it when panels differ a lot in length, such as the same code in several languages.
Two manuscripts at a time, for up to four weeks.
Readers may borrow two manuscripts at a time, for up to four weeks each.
Rare copies stay in the reading room of the House of Wisdom and can't leave it.
Renew once by asking the librarian before the due date; a copy someone else has asked for can't be renewed.
<script lang="ts">
import * as Tabs from '#lib/ui/tabs/index.js';
</script>
<!-- fit: the area takes the chosen panel's height, so a short panel leaves no gap below it. -->
<Tabs.Root fit>
<Tabs.List label="Lending rules">
<Tabs.Tab value="short">In brief</Tabs.Tab>
<Tabs.Tab value="full">In full</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="short">
<p>Two manuscripts at a time, for up to four weeks.</p>
</Tabs.Panel>
<Tabs.Panel value="full">
<p>Readers may borrow two manuscripts at a time, for up to four weeks each.</p>
<p>Rare copies stay in the reading room of the House of Wisdom and can't leave it.</p>
<p>
Renew once by asking the librarian before the due date; a copy someone else has asked for
can't be renewed.
</p>
</Tabs.Panel>
</Tabs.Root>Folder
The chosen tab rises out of the panel like a folder tab. Switching stretches it toward the new tab, leading edge first, and it settles on a spring; with reduced motion it simply moves.
<script lang="ts">
import * as Tabs from '#lib/ui/tabs/index.js';
let city = $state('baghdad');
</script>
<Tabs.Root bind:value={city} variant="folder">
<Tabs.List label="Houses of learning">
<Tabs.Tab value="baghdad">Baghdad</Tabs.Tab>
<Tabs.Tab value="cordoba">Córdoba</Tabs.Tab>
<Tabs.Tab value="fez">Fez</Tabs.Tab>
<Tabs.Tab value="samarkand">Samarkand</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="baghdad"
>The House of Wisdom gathered translators of Greek, Persian and Sanskrit.</Tabs.Panel
>
<Tabs.Panel value="cordoba">Its library held some four hundred thousand volumes.</Tabs.Panel>
<Tabs.Panel value="fez">Al-Qarawiyyin, founded in 859, still awards degrees.</Tabs.Panel>
<Tabs.Panel value="samarkand">Ulugh Beg's observatory charted over a thousand stars.</Tabs.Panel>
</Tabs.Root>Pill
The chosen tab lifts onto the surface inside a quiet track, with the same corners as a button, and stretches toward the next one the same way the folder tab does.
<script lang="ts">
import * as Tabs from '#lib/ui/tabs/index.js';
let range = $state('day');
</script>
<Tabs.Root bind:value={range} variant="pill">
<Tabs.List label="Prayer times">
<Tabs.Tab value="day">Day</Tabs.Tab>
<Tabs.Tab value="week">Week</Tabs.Tab>
<Tabs.Tab value="month">Month</Tabs.Tab>
<Tabs.Tab value="ramadan">Ramadan</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="day">Fajr 4:52, Dhuhr 11:58, Asr 3:41, Maghrib 5:22, Isha 6:37.</Tabs.Panel>
<Tabs.Panel value="week">Maghrib moves about four minutes earlier this week.</Tabs.Panel>
<Tabs.Panel value="month">Fajr shifts from 4:52 to 5:08 over the month.</Tabs.Panel>
<Tabs.Panel value="ramadan">Suhoor ends at the start of Fajr; iftar is at Maghrib.</Tabs.Panel>
</Tabs.Root>Props
Tabs.Root
| Prop | Type | Default |
|---|---|---|
value | string, bindable | first enabled tab |
orientation | 'horizontal' | 'vertical' | 'horizontal' |
activation | 'automatic' | 'manual' | 'automatic' |
size | 'sm' | 'md' | 'md' |
variant | 'line' | 'folder' | 'pill' (folder and pill: horizontal only) | 'line' |
fit | boolean: size to the chosen panel, not the tallest | false |
Tabs.List, Tabs.Tab, Tabs.Panel
| Part | Props |
|---|---|
Tabs.List | label: names the tab set |
Tabs.Tab | value (required), disabled |
Tabs.Panel | value (required), matching its tab |
Accessibility
- Follows the WAI-ARIA tabs pattern with a roving tab stop: Tab enters at the selected tab, arrows move within the list.
- Left and right arrows follow reading direction in right-to-left pages.
- Hidden panels stay in the page, so each tab's
aria-controlsalways points at something that exists. - The indicator only moves with transforms, and snaps for keyboard moves and reduced motion.
| Key | Action |
|---|---|
| → / ← (↓ / ↑ vertical) | Next / previous tab, wrapping and skipping disabled tabs. |
| Home / End | First / last tab. |
| Enter / Space | Selects the focused tab (manual activation). |