Miss. Train. Move.

Liquid tabs

Tabs, segmented controls. Stretches into the next lane, then pulls its tail in.

Sport
Swimming
Move
Stretches into the next lane, then pulls its tail in.
For
Tabs, segmented controls

two edge springs · lead 520 / tail 150 · reduced: jumps

01 Install

Terminal
npx shadcn@latest add https://moveui-red.vercel.app/r/liquid-tabs.json

It brings the tokens with it. The first time, import the tokens once in your root layout:

app/layout.tsx
import "@/components/moveui/tokens.css";

Not using shadcn? Copy the files below into components/moveui/, and tokens.css next to them.

02 Use it

Example
import { LiquidTabs } from "@/components/moveui/liquid-tabs/liquid-tabs";

<LiquidTabs
  aria-label="Match view"
  tabs={[
    { id: "live", label: "Live" },
    { id: "stats", label: "Stats" },
    { id: "table", label: "Table" },
  ]}
  defaultValue="live"
  onValueChange={(id) => setView(id)}
/>

03 Or ask your agent

Paste this into Claude Code, Cursor or any coding agent. It installs the piece and wires it in.

Prompt
Add the Move UI "Liquid tabs" piece to this project. It's for: Tabs, segmented controls.

1. Install it: npx shadcn@latest add https://moveui-red.vercel.app/r/liquid-tabs.json
2. If the project doesn't import the Move UI tokens yet, add this once to the root layout: import "@/components/moveui/tokens.css";
3. Use it like this, adapted to where it belongs in my code:

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

<LiquidTabs
  aria-label="Match view"
  tabs={[
    { id: "live", label: "Live" },
    { id: "stats", label: "Stats" },
    { id: "table", label: "Table" },
  ]}
  defaultValue="live"
  onValueChange={(id) => setView(id)}
/>

Keep its reduced-motion behaviour and keyboard support. Don't hardcode durations, easing or colours: they come from the --ml-* tokens.
Docs: https://moveui-red.vercel.app/pieces/liquid-tabs

Want your agent to know the whole library and its motion rules? Add the Move UI skill to your project:

Terminal
npx shadcn@latest add https://moveui-red.vercel.app/r/skill.json

04 Code

components/moveui/liquid-tabs/liquid-tabs.tsx
"use client";

import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
import "./liquid-tabs.css";

type Tab = { id: string; label: string };

type Props = {
  tabs: Tab[];
  value?: string;
  defaultValue?: string;
  onValueChange?: (id: string) => void;
  "aria-label": string;
  className?: string;
};

type Edge = { p: number; v: number; g: number; k: number };

const num = (el: Element, name: string, fallback: number) => {
  const v = parseFloat(getComputedStyle(el).getPropertyValue(name));
  return Number.isFinite(v) ? v : fallback;
};

/**
 * Liquid tabs. WAI-ARIA tabs pattern: arrow keys, Home and End move and select.
 * The drop is two springs, one per edge. Stiffness comes from the --ml-spring-liquid-* tokens.
 */
export function LiquidTabs({ tabs, value, defaultValue, onValueChange, className, ...aria }: Props) {
  const [inner, setInner] = useState(defaultValue ?? tabs[0]?.id);
  const selected = value ?? inner;
  const baseId = useId();

  const listRef = useRef<HTMLDivElement>(null);
  const dropRef = useRef<HTMLSpanElement>(null);
  const tabRefs = useRef(new Map<string, HTMLButtonElement>());
  const edges = useRef({ l: { p: 0, v: 0, g: 0, k: 0 } as Edge, r: { p: 0, v: 0, g: 0, k: 0 } as Edge });
  const raf = useRef(0);
  const shown = useRef(false);

  const paint = useCallback(() => {
    const drop = dropRef.current;
    if (!drop) return;
    const { l, r } = edges.current;
    const w = Math.max(0, r.p - l.p);
    const stretch = Math.max(0, w - (r.g - l.g));
    const sy = 1 - Math.min(0.12, stretch / 600); // keep the drop's volume while it stretches
    drop.style.width = `${w}px`;
    drop.style.transform = `translateX(${l.p}px) scaleY(${sy})`;
  }, []);

  const aim = useCallback(
    (id: string | undefined, snap = false) => {
      const list = listRef.current, drop = dropRef.current, tab = id ? tabRefs.current.get(id) : undefined;
      if (!list || !drop || !tab) return;
      const lead = num(list, "--ml-spring-liquid-lead", 520);
      const tail = num(list, "--ml-spring-liquid-tail", 150);
      const ratio = num(list, "--ml-spring-liquid-ratio", 0.72);
      const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;

      const L = tab.offsetLeft, R = L + tab.offsetWidth;
      const { l, r } = edges.current;
      const right = L > l.g;
      l.g = L; r.g = R;
      l.k = right ? tail : lead;
      r.k = right ? lead : tail;

      if (snap || reduce || !shown.current) {
        l.p = L; r.p = R; l.v = r.v = 0;
        shown.current = true;
        drop.style.opacity = "1";
        paint();
        return;
      }

      if (raf.current) return;
      let last = performance.now();
      const step = (t: number) => {
        const dt = Math.min((t - last) / 1000, 1 / 30);
        last = t;
        let moving = false;
        for (const e of [l, r]) {
          const damp = 2 * Math.sqrt(e.k) * ratio;
          e.v += (e.k * (e.g - e.p) - damp * e.v) * dt;
          e.p += e.v * dt;
          if (Math.abs(e.v) > 0.02 || Math.abs(e.g - e.p) > 0.02) moving = true;
        }
        paint();
        raf.current = moving ? requestAnimationFrame(step) : 0;
      };
      raf.current = requestAnimationFrame(step);
    },
    [paint],
  );

  const current = useRef(selected);
  useLayoutEffect(() => {
    current.current = selected;
    aim(selected);
  }, [selected, aim]);

  // Resize snaps the drop into place. Runs once, so it never cancels a slide in progress.
  useEffect(() => {
    const list = listRef.current;
    if (!list) return;
    const ro = new ResizeObserver(() => aim(current.current, true));
    ro.observe(list);
    return () => {
      ro.disconnect();
      cancelAnimationFrame(raf.current);
      raf.current = 0;
    };
  }, [aim]);

  const select = (id: string) => {
    if (value === undefined) setInner(id);
    onValueChange?.(id);
  };

  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
    const i = tabs.findIndex((t) => t.id === selected);
    const to =
      e.key === "ArrowRight" ? (i + 1) % tabs.length
      : e.key === "ArrowLeft" ? (i - 1 + tabs.length) % tabs.length
      : e.key === "Home" ? 0
      : e.key === "End" ? tabs.length - 1
      : -1;
    if (to < 0) return;
    e.preventDefault();
    select(tabs[to].id);
    tabRefs.current.get(tabs[to].id)?.focus();
  };

  return (
    <div ref={listRef} role="tablist" className={["ml-liquid", className].filter(Boolean).join(" ")} onKeyDown={onKeyDown} {...aria}>
      <span ref={dropRef} className="ml-liquid__drop" aria-hidden="true" />
      {tabs.map((t) => (
        <button
          key={t.id}
          ref={(el) => {
            if (el) tabRefs.current.set(t.id, el);
            else tabRefs.current.delete(t.id);
          }}
          id={`${baseId}-tab-${t.id}`}
          role="tab"
          type="button"
          aria-selected={t.id === selected}
          tabIndex={t.id === selected ? 0 : -1}
          className="ml-liquid__tab"
          onClick={() => select(t.id)}
        >
          {t.label}
        </button>
      ))}
    </div>
  );
}
components/moveui/liquid-tabs/liquid-tabs.css
/*
  Liquid tabs: the highlight is a drop. Its two edges are separate springs.
  The edge moving toward the target is stiff, the trailing edge is soft,
  so the drop stretches out, then pulls its tail in. It squashes slightly while stretched.
  Reduced motion: the drop jumps to the selected tab.
*/
.ml-liquid {
  position: relative;
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: var(--ml-radius-control);
  background: var(--ml-bg);
  border: 1px solid var(--ml-fg);
  isolation: isolate;
}

.ml-liquid__drop {
  position: absolute;
  inset-block: 4px;
  left: 0;
  z-index: -1;
  border-radius: var(--ml-radius-control);
  background: var(--ml-ink);
  transform-origin: left center;
  will-change: transform, width;
  opacity: 0;
}

.ml-liquid__tab {
  appearance: none;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0.6em 1.1em;
  border-radius: var(--ml-radius-control);
  color: var(--ml-fg-muted);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.8125rem;
  line-height: 1;
  letter-spacing: var(--ml-tracking);
  text-transform: uppercase;
  transition: color var(--ml-dur-quick) var(--ml-ease-out);
}

.ml-liquid__tab:hover {
  color: var(--ml-fg);
}

.ml-liquid__tab[aria-selected="true"] {
  color: var(--ml-ink-fg);
}

.ml-liquid__tab:focus-visible {
  outline: 2px solid var(--ml-focus);
  outline-offset: 2px;
}