Skip to content
English

How it works

The indicator fills the whole tab bar and a clip-path: inset() cuts out the current tab, so transitioning clip-path animates position and width together without stretching the pill's corners. The pill variant carries a copy of the tabs in inverted text inside the indicator, clipped by the same path, so text colour and pill always match mid-slide. The pill is ink on a filled track by default; set --ds-tabs-pill and --ds-tabs-on-pill to use the accent or a brand colour. JS only measures the tab's left and right distances into CSS variables.

Use it for

  • Lists such as orders, messages or favourites filtered by status (All, Unpaid, Shipping, Delivered).
  • Switching between 2 to 5 sibling views on a page, such as a product's Overview, Specs and Reviews.
  • A segmented choice for view mode or time range instead of radios (tab bar only, no content).

Look elsewhere when

  • More than 6 tabs or long labels: they get squeezed, use a scrollable tab bar or a dropdown.
  • Navigation to different page addresses: use link navigation, not role=tab.
  • A single-choice question in a form: the semantics differ, use a radio group.

Usage

import { useState } from 'react'
import { SlidingTabs } from './SlidingTabs.jsx'

export function Orders() {
  const [tab, setTab] = useState('all')
  return (
    <SlidingTabs
      label="Order status"
      value={tab}
      onChange={setTab}
      fullWidth
      items={[
        { value: 'all', label: 'All', content: <OrderList /> },
        { value: 'unpaid', label: 'Unpaid', badge: 2, content: <OrderList status="unpaid" /> },
        { value: 'shipping', label: 'Shipping', content: <OrderList status="shipping" /> },
        { value: 'delivered', label: 'Delivered', content: <OrderList status="delivered" /> },
      ]}
    />
  )
}

Props

PropTypeDefaultWhat it does
items{ value, label, badge?, content?, disabled? }[]—The tabs. If no item has content, only the tab bar is rendered, which suits a filter.
valuestring—Controlled: the selected value.
defaultValuestringfirst enabled itemUncontrolled: the initial value. If the selected item is later removed from items, it falls back to the first enabled one.
onChange(value: string) => void—Called when the selection changes.
variant'pill' | 'underline''pill'Look: an ink pill on a filled track, or a thick underline.
durationnumber240Indicator glide time in ms; panels enter in 1.25 times that. Follows --ds-duration-base when omitted.
fullWidthbooleanfalseStretches the tab bar and splits the width equally, common on mobile.
labelstring—Accessible name of the tab bar (aria-label), such as “Order status”.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root <div>.

Accessibility

  • The full WAI-ARIA Tabs pattern: role tablist, tab and tabpanel linked by aria-selected, aria-controls and aria-labelledby.
  • Left and Right switch tabs with wrap-around, skipping disabled ones; Home and End jump to the ends; focus selects the tab.
  • Roving tabindex: only the selected tab is in the Tab order, and one more Tab enters the panel (tabIndex=0).
  • The indicator and its inverted-text copy are aria-hidden, so screen readers do not read them twice.
  • Pill tabs get an invisible click area above and below for a 44px touch height, and a :focus-visible ring.
  • With reduced motion the indicator jumps into place and panels do not slide.

Motion

Indicator clip-path 240ms ease-out; panel entrance 300ms ease-out moving 16px; text colour 160ms; a pressed tab label scales to 0.96 for 100ms.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

SlidingTabs.jsxsliding-tabs.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Navigation