# Tabs

> Animated tabs for React and shadcn: an underline or pill indicator glides to the active tab and panels cross-fade.

Tabs with a gliding indicator (underline or pill) and panels that cross-fade 6px in the direction of travel while their container's height springs. Base UI Tabs behaviour.

Also known as sliding tabs.

- Tier: Free (MIT)
- Interaction: Slide
- Page: https://eased.dev/components/tabs
- Installs: motion, @base-ui/react
- Registry: https://eased.dev/r/tabs.json

## Install

```bash
npx shadcn add https://eased.dev/r/tabs.json
```

Tabs on Base UI's Tabs (roving focus, arrow keys, Home/End, ARIA wiring), with a gliding indicator and panels that cross-fade in the direction of travel.

## When to use

- Switching between views of one thing that share a place on the page: a project's Overview, Activity and Settings.
- Section navigation inside a card or panel (`underline`), or a dense view switch in a toolbar (`pill`).
- Routed sections, where each tab is a link: `render={<Link href="…" />}`.

## When not to use

- Picking a value for a form or a filter, where nothing else on the page changes: use [Segmented](/components/segmented).
- Content people need to compare side by side, or read in sequence: put it on the page, or use an [Accordion](/components/accordion).
- More than about six tabs: the list scrolls, but a sidebar or a menu reads better.

## Usage

```tsx project-tabs.tsx
import { Tab, Tabs, TabsList, TabsPanel, TabsPanels } from "@/components/eased/tabs/tabs";

export function ProjectTabs() {
  return (
    <Tabs defaultValue="overview">
      <TabsList aria-label="Project">
        <Tab value="overview">Overview</Tab>
        <Tab value="activity">Activity</Tab>
      </TabsList>
      <TabsPanels className="mt-3">
        <TabsPanel value="overview">…</TabsPanel>
        <TabsPanel value="activity">…</TabsPanel>
      </TabsPanels>
    </Tabs>
  );
}
```

## Examples

### Pill

A filled highlight behind the active tab, for toolbars and filters.

```tsx
<Tabs defaultValue="preview" variant="pill">
  <TabsList aria-label="View">
    <Tab value="preview">Preview</Tab>
    <Tab value="code">Code</Tab>
  </TabsList>
</Tabs>
```

### Routed tabs

Each tab is a link; the indicator and the label render inside it. Control `value` from the pathname.

```tsx
<Tabs value={pathname}>
  <TabsList aria-label="Settings">
    <Tab value="/settings/general" render={<Link href="/settings/general" />}>General</Tab>
    <Tab value="/settings/domains" render={<Link href="/settings/domains" />}>Domains</Tab>
  </TabsList>
</Tabs>
```

## API reference

### Tabs

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` / `defaultValue` | `string` | | Controlled or uncontrolled active tab. |
| `onValueChange` | `(value) => void` | | |
| `variant` | `"underline" \| "pill"` | `"underline"` | A 2px bar under the active tab, or a filled highlight behind it. |
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Vertical lays the list beside the panels. |

Base UI Root props pass through.

### TabsList

| Prop | Type | Default | Description |
|---|---|---|---|
| `aria-label` | `string` | | Names the tab list. |
| `activateOnFocus` | `boolean` | `false` | Select a tab as soon as an arrow key focuses it. |
| `loopFocus` | `boolean` | `true` | Arrow keys wrap from the last tab to the first. |

Scrolls sideways with edge fades when the tabs outgrow it, so it never widens the page.

### Tab

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `string` | | Matches a `TabsPanel`. |
| `icon` | `ReactNode` | | A 16px icon before the label. |
| `disabled` | `boolean` | `false` | |
| `render` | `ReactElement` | | Render as another element, e.g. a Next `<Link />`. |

### TabsPanels and TabsPanel

`TabsPanels` takes a `className`; its height springs between panels of different lengths. `TabsPanel` takes `value` and `keepMounted`, which keeps a hidden panel's state (a half-filled form, a running demo).

## Keyboard

| Key | Action |
|---|---|
| `Tab` | Moves focus into the list (to the active tab), then on to the panel. |
| `←` / `→` | Moves focus between tabs (`↑` / `↓` when vertical). |
| `Home` / `End` | Moves focus to the first or last tab. |
| `Enter` / `Space` | Selects the focused tab, unless `activateOnFocus` already did. |

## Accessibility

- Base UI wires `role="tablist"`, `role="tab"`, `role="tabpanel"`, `aria-selected` and `aria-controls`; name the list with `aria-label`.
- One tab stop for the whole list (roving focus), so keyboard users are not walked through every tab.
- The active tab's label darkens but never changes weight, so nothing shifts as you move.

## Motion

The indicator glides to the new tab on the snappy spring. The new panel enters from 6px on the side of the tab you came from while the old one leaves 3px the other way, faster than it arrived, and the container's height springs between them. Reduced motion keeps only an opacity cross-fade, and the indicator jumps instead of gliding.

## Notes for AI

Use Tabs when the selection swaps a region of content, and give every `Tab` a matching `TabsPanel` inside `TabsPanels`. Pick `underline` for page and card sections and `pill` for toolbars; pass `keepMounted` to panels whose state must survive switching.

Do not build the indicator or the panel animation yourself, and do not use Tabs as a form control: [Segmented](/components/segmented) submits a value with a form and has radio semantics.

## Related

- [Segmented](/components/segmented): a single choice that changes a value, not a view.
- [Toggle Group](/components/toggle-group): several on/off options in a row.
- [Accordion](/components/accordion): sections people open in place.

## Example

`components/eased/tabs/tabs-demo.tsx`

```tsx
"use client";

import { Avatar } from "../avatar/avatar";
import { DemoFrame } from "../lib/demo-frame";
import { rowGrid, rowGridRow } from "../lib/layout";
import { Tab, Tabs, TabsList, TabsPanel, TabsPanels } from "./tabs";

const STATS = [
  { label: "Deploys this week", value: "18", note: "4 more than last week" },
  { label: "Success rate", value: "97.2%", note: "1 failed on Tuesday" },
  { label: "Median build", value: "1m 42s", note: "12s slower" },
  { label: "Edge requests", value: "2.4M", note: "8% up on last week" },
  { label: "Bandwidth", value: "86 GB", note: "62% of the monthly limit" },
];

const ACTIVITY: { who: string; what: string; target: string; when: string; prose?: boolean }[] = [
  { who: "Maya Okafor", what: "deployed", target: "main@4f2a91c", when: "4m ago" },
  { who: "Jonas Berg", what: "opened", target: "Checkout copy tweaks", when: "38m ago", prose: true },
  { who: "Preview bot", what: "built", target: "feat/gift-cards", when: "1h ago" },
  { who: "Lena Park", what: "rolled back", target: "main@a19e03d", when: "Yesterday" },
  { who: "Maya Okafor", what: "added a domain", target: "shop.acme.co", when: "Mon" },
];

const MEMBERS = [
  { name: "Maya Okafor", email: "maya@acme.co", role: "Owner" },
  { name: "Jonas Berg", email: "jonas@acme.co", role: "Developer" },
  { name: "Lena Park", email: "lena@acme.co", role: "Developer" },
  { name: "Tomás Rivera", email: "tomas@acme.co", role: "Developer" },
  { name: "Aiko Tanaka", email: "aiko@acme.co", role: "Viewer" },
];

const SETTINGS = [
  ["Framework", "Next.js"],
  ["Root directory", "apps/web"],
  ["Build command", "pnpm build"],
  ["Output directory", ".next"],
  ["Node.js", "22.x"],
  ["Region", "Frankfurt (fra1)"],
] as const;

export function TabsDemo() {
  return (
    <DemoFrame title="acme-storefront" meta="Production">
      <div className="min-h-0 flex-1 overflow-y-auto px-4 pt-2 pb-4">
        <Tabs defaultValue="overview">
          <TabsList aria-label="Project">
            <Tab value="overview">Overview</Tab>
            <Tab value="activity">Activity</Tab>
            <Tab value="members">Members</Tab>
            <Tab value="settings">Settings</Tab>
          </TabsList>

          <TabsPanels className="mt-3">
            <TabsPanel value="overview">
              <dl className="flex flex-col">
                {STATS.map((s) => (
                  <div key={s.label} className="flex items-baseline justify-between gap-3 border-b border-line-subtle py-2.5 last:border-b-0">
                    <div className="min-w-0">
                      <dt className="text-ui-sm text-text-secondary">{s.label}</dt>
                      <p className="text-ui-xs text-text-muted">{s.note}</p>
                    </div>
                    <dd className="text-ui-lg font-medium text-text tabular-nums">{s.value}</dd>
                  </div>
                ))}
              </dl>
            </TabsPanel>

            <TabsPanel value="activity">
              <ol className="flex flex-col">
                {ACTIVITY.map((a, i) => (
                  <li key={i} className="flex h-11 min-w-0 items-center gap-3">
                    <Avatar name={a.who} size="sm" />
                    <p className="min-w-0 flex-1 truncate text-ui-sm text-text-secondary">
                      <span className="text-text">{a.who}</span> {a.what} <span className={a.prose ? "text-text" : "font-mono text-ui-xs text-text"}>{a.target}</span>
                    </p>
                    <span className="shrink-0 text-ui-xs text-text-muted tabular-nums">{a.when}</span>
                  </li>
                ))}
              </ol>
            </TabsPanel>

            <TabsPanel value="members">
              <ul className={`${rowGrid} gap-x-3`}>
                {MEMBERS.map((m) => (
                  <li key={m.email} className={`${rowGridRow} h-12`}>
                    <Avatar name={m.name} size="md" />
                    <div className="min-w-0">
                      <p className="truncate text-ui-sm text-text">{m.name}</p>
                      <p className="truncate text-ui-xs text-text-muted">{m.email}</p>
                    </div>
                    <span className="truncate text-ui-xs text-text-muted">{m.role}</span>
                  </li>
                ))}
              </ul>
            </TabsPanel>
            <TabsPanel value="settings">
              {/* A fixed key track, so every value starts on one x instead of hugging the right edge. */}
              <dl className="grid grid-cols-[8rem_minmax(0,1fr)] gap-x-3">
                {SETTINGS.map(([k, v]) => (
                  <div key={k} className={`${rowGridRow} h-10 border-b border-line-subtle last:border-b-0`}>
                    <dt className="text-ui-sm text-text-secondary">{k}</dt>
                    <dd className="truncate font-mono text-ui-xs text-text">{v}</dd>
                  </div>
                ))}
              </dl>
            </TabsPanel>
          </TabsPanels>
        </Tabs>
      </div>
    </DemoFrame>
  );
}
```
