# Liquid tabs

> Tabs whose highlight has a little surface tension: it draws out and pinches for a moment, then it is a pill again.

A tab highlight usually slides like a box on a rail. Here the edge in front leads and the edge behind follows a moment later, so the highlight draws out slightly and its middle pinches before it settles. It takes about 0.3s with no overshoot, so you can notice it the first time and use it all day without it getting in the way. Each label turns exactly where the highlight touches it, and with a colour per tab the new colour comes in from the front while the old one leaves with the tail.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/liquid-tabs.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/liquid-tabs
- Registry item (source): https://hairlineui.com/r/liquid-tabs.json

## Usage

```tsx
import { LiquidTabs } from "@/components/liquid-tabs";

<LiquidTabs label="Sections" defaultValue="overview" tabs={[
  { value: "overview", label: "Overview" },
  { value: "activity", label: "Activity" },
  { value: "settings", label: "Settings" },
]} />
```

## As site navigation

Give each tab an href and the row becomes links. Pass the current path as value so it follows the route.

```tsx
"use client";
import { usePathname } from "next/navigation";
import { LiquidTabs } from "@/components/liquid-tabs";

export function SiteNav() {
  const pathname = usePathname();
  return (
    <LiquidTabs
      label="Main"
      value={pathname}
      tabs={[
        { value: "/", label: "Home", href: "/" },
        { value: "/pricing", label: "Pricing", href: "/pricing" },
        { value: "/docs", label: "Docs", href: "/docs" },
      ]}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tabs` | `LiquidTab[]` | – | value, label, icon, ariaLabel, href, disabled, color, foreground, panelId. |
| `value / defaultValue` | `string` | – | The chosen tab. |
| `onValueChange` | `(value: string) => void` | – | Called when a tab is chosen. |
| `label` | `string` | – | Accessible name of the row. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 32px, 40px or 48px tall. |
| `block` | `boolean` | `false` | Fill the parent with equal tabs. |

## States

- **pick**: The front edge leads and the back follows. Both are critically damped, so it settles in about 0.3s without overshooting.
- **long jump**: The highlight can draw out at most 0.45 of its height past its width, and the tail is carried behind the front, so distance adds speed but not shape.
- **pinch**: The waist narrows by up to 20% while drawn out and fills back in as it closes.
- **reduced motion**: The selection and the label colours change in place.

## What it handles

A highlight on a transition restarts from a standstill whenever it is interrupted, and its label jumps colour all at once. This one is drawn from springs that keep their speed, and it stays quiet enough for a control people click all day.

- **Interruptions**: Click three tabs quickly and the highlight curves from one to the next. It keeps its speed, because the edges are springs and the outline is a pure function of them.
- **Quiet on purpose**: About 0.3s with no overshoot, and a limit on how far it draws out, so a long jump is no louder than a short one.
- **Letters that turn in place**: The same outline clips a second copy of the labels, so a word can be half one colour while the highlight crosses it.
- **Tab and link semantics**: A tablist with arrow keys, Home, End and one tab stop; give tabs an href and they become links with aria-current.
- **Narrow rows**: The row scrolls sideways inside its pill and brings the chosen tab into view, with the highlight in the same scroll.
- **First paint**: Before anything is measured the chosen tab paints its own highlight, so a server render never shows a row with nothing selected.
- **No cost at rest**: The springs share one frame loop that sleeps when they settle. Moving means writing one path, with no React render and no layout.

## Replaces

sliding tab indicator, gooey filter effects, framer-motion layoutId tabs

## Where it fits

- **App sections**: Overview, activity, members and settings at the top of a page.
- **Site navigation**: Give each tab an href and it becomes a nav bar with aria-current.
- **Feed filters**: A colour per category, so the filter says which one you are in.
- **Chart ranges**: 7, 30 and 90 days filling the width of a card.

## Notes

- Reduced motion: the selection changes in place.
- Colours come from your theme, or from each tab's color and foreground. The trough has a little real shading, so it still sits inside any screen.
- Keep the labels the same weight: both copies of them have to lie exactly on top of each other.
- Panels are yours: pass panelId and give the panel role="tabpanel".

License: MIT (https://hairlineui.com/license#components)
