Keyframery

Tabs

The key stretches across the list to the tab you pick, and the panel slides in from that side.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/tabs

This adds components/keyframery/tabs.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab } from "@/components/keyframery/tabs"

export default function Usage() {
  return (
    <Tabs defaultValue="account">
      <TabsList aria-label="Settings">
        <TabsTab value="account">Account</TabsTab>
        <TabsTab value="password">Password</TabsTab>
      </TabsList>
      <TabsPanels>
        <TabsPanel value="account">Account settings</TabsPanel>
        <TabsPanel value="password">Password settings</TabsPanel>
      </TabsPanels>
    </Tabs>
  )
}

Anatomy

How the parts fit together:

Tabs
├── TabsList
│   └── TabsTab
└── TabsPanels
    └── TabsPanel

Examples

Basic

The key glides to the chosen tab, and the panels slide in from the side you moved towards.

Controlled

Pass value and onValueChange, for example to keep the tab in the URL.

Vertical

orientation="vertical" lists the tabs down the side. Up and down arrows move between them.

Icons

TabsTabIcon holds an icon inside a tab. Screen readers skip it, so a tab with only an icon needs an aria-label.

Motion

MoveWhat you see
StretchThe key stretches across the list toward the tab you pick, then closes up.
FadeLabel colours flip exactly at the key's edge as it passes.
DirectionThe panel slides in from the side you moved to.

Timing and springiness follow the motion style you set. To change how fast this tabs moves, pass speed:

<Tabs speed="fast">
  …
</Tabs>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--tabs-trackTab list well--muted
--tabs-keySelected tab surface--background; --accent in dark
--tabs-inkUnselected labels--muted-foreground
--tabs-selected-inkSelected labels--foreground
--tabs-heightTab height2rem
--tabs-radiusList corners12px
--tabs-key-radiusTab key corners9px
--tabs-gapSpace between tabs0.125rem

API reference

Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK tabs reference.

Tabs

Renders a <div>, and takes its props too.

Prop

Type

TabsTab

Renders a <button>, and takes its props too.

Prop

Type

TabsPanel

Renders a <div>, and takes its props too.

Prop

Type

TabsTabIcon

Renders a <span>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • TabsList: a <div>
  • TabsPanels: a <div>
  • TabsIndicator: a <span>

Keyboard

KeyWhat it does
← →Moves to the previous or next tab.
HomeMoves to the first tab.
EndMoves to the last tab.
EnterSelects the focused tab, with manual activation.

Accessibility

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.

Swap the import

Already using UI SDK's tabs with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

// Before
import { … } from "@ui-sdk/react/tabs"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/tabs"

Questions

How does the animated Tabs for UI SDK move?

Stretch: The key stretches across the list toward the tab you pick, then closes up. Fade: Label colours flip exactly at the key's edge as it passes. Direction: The panel slides in from the side you moved to.

Do I need Motion or Framer Motion for the animated Tabs?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

Can I keep my own styling and only take the motion?

Yes. Import from @/components/keyframery/primitives/tabs instead. It has the same parts and props as @ui-sdk/react/tabs and adds motion only.

What happens to the Tabs when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page