UI.MD

Tabs

A set of tabbed panels with a sliding pill indicator animated by Motion.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/tabs.json

Usage

import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"

Examples

Default

Account settings go here.

Sizes

size steps the tabs along the control scale: sm (h-7, 12px), default (h-8, 13px), lg (h-10, 14px). The height sits on the trigger, so a tab is exactly as tall as a Nav item at the same size and the two line up in a header; the list grows by its 4px gutter. One prop on Tabs sizes the triggers, list, and count chips.

Small
Default
Large

With Icons

Pass an icon to a trigger to render it before the label.

Account settings go here.

With Count

Pass a count to add a counter chip. It fills solid accent on the active tab. Add an aria-label where a bare number needs context (aria-label="Open, 18 issues").

Issues still open.

With Icons and Count

icon and count compose. Cap large counts at "99+" so a growing number can't widen the tab.

12 unread messages.

Icon Only

Omit the children for an icon-only trigger; the pill tightens to a square. Each text-less trigger needs an aria-label for an accessible name.

Grid view.

API Reference

PropTypeDefaultDescription
defaultValueTabsstring-The tab that is active when initially rendered, for uncontrolled usage.
valueTabsstring-The controlled active tab. Pair with onValueChange.
onValueChangeTabs(value: string) => void-Called with the new value when the active tab changes.
sizeTabs"sm" | "default" | "lg""default"Steps the triggers, list, and count chips along the control scale, from sm (h-7, 12px type) up to lg (h-10, 14px type). The height sits on the trigger, matching Nav item for item; the list adds its 4px gutter on top.
value*TabsTriggerstring-Identifier linking each <TabsTrigger /> to its matching <TabsContent />.
fullWidthTabsListbooleanfalseStretches the list to fill its container so triggers share the width evenly.
iconTabsTriggerReact.ReactNode-Leading icon rendered before the trigger label, e.g. <Star />.
countTabsTriggerReact.ReactNode-Trailing counter chip, e.g. 18 or "99+". Fills solid accent on the active tab.