For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
FrakmentFrakment

Tabs

A set of layered sections of content displayed one at a time.

Web
Frakment
Overview
View your key metrics and recent project activity.
You have 12 active projects and 3 pending tasks.
tabs.tsx
"use client";

import * as React from "react";

import { cn } from "@/lib/utils";

interface TabsContextValue {
  baseId: string;
  orientation: "horizontal" | "vertical";
  setValue: (value: string) => void;
  value: string;
}

const TabsContext = React.createContext<TabsContextValue | null>(null);

function useTabsContext(): TabsContextValue {
  const ctx = React.useContext(TabsContext);
  if (!ctx) {
    throw new Error("Tabs components must be used within <Tabs>.");
  }
  return ctx;
}

interface TabsProps {
  children?: React.ReactNode;
  className?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
  orientation?: "horizontal" | "vertical";
  value?: string;
}

function Tabs({
  children,
  className,
  value: valueProp,
  defaultValue = "",
  onValueChange,
  orientation = "horizontal",
}: TabsProps) {
  const isControlled = valueProp !== undefined;
  const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
  const value = isControlled ? valueProp : uncontrolled;
  const baseId = React.useId();
  const setValue = React.useCallback(
    (next: string) => {
      if (!isControlled) {
        setUncontrolled(next);
      }
      onValueChange?.(next);
    },
    [isControlled, onValueChange]
  );
  const ctx = React.useMemo<TabsContextValue>(
    () => ({ baseId, orientation, setValue, value }),
    [value, setValue, baseId, orientation]
  );
  return (
    <TabsContext.Provider value={ctx}>
      <div
        className={cn(
          "flex flex-col gap-2",
          orientation === "vertical" && "flex-row",
          className
        )}
        data-orientation={orientation}
        data-slot="tabs"
      >
        {children}
      </div>
    </TabsContext.Provider>
  );
}

type TabsListProps = React.ComponentPropsWithoutRef<"div">;

function TabsList({ children, className, onKeyDown, ...props }: TabsListProps) {
  const ctx = useTabsContext();
  const listRef = React.useRef<HTMLDivElement>(null);
  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
    onKeyDown?.(e);
    if (e.defaultPrevented) {
      return;
    }
    const root = listRef.current;
    if (!root) {
      return;
    }
    const triggers = Array.from(
      root.querySelectorAll<HTMLButtonElement>(
        "[data-slot=tabs-trigger]:not([disabled])"
      )
    );
    if (triggers.length === 0) {
      return;
    }
    const currentIdx = triggers.indexOf(
      document.activeElement as HTMLButtonElement
    );
    if (currentIdx < 0) {
      return;
    }
    let nextIdx = -1;
    const isVertical = ctx.orientation === "vertical";
    const prev = isVertical ? "ArrowUp" : "ArrowLeft";
    const next = isVertical ? "ArrowDown" : "ArrowRight";
    if (e.key === next) {
      nextIdx = (currentIdx + 1) % triggers.length;
    } else if (e.key === prev) {
      nextIdx = (currentIdx - 1 + triggers.length) % triggers.length;
    } else if (e.key === "Home") {
      nextIdx = 0;
    } else if (e.key === "End") {
      nextIdx = triggers.length - 1;
    }
    if (nextIdx < 0) {
      return;
    }
    e.preventDefault();
    triggers[nextIdx].focus();
    triggers[nextIdx].click();
  };
  return (
    <div
      {...props}
      className={cn(
        "bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px] outline-none",
        className
      )}
      data-slot="tabs-list"
      onKeyDown={handleKeyDown}
      ref={listRef}
      role="tablist"
    >
      {children}
    </div>
  );
}

type TabsTriggerProps = Omit<
  React.ComponentPropsWithoutRef<"button">,
  "value" | "ref"
> & {
  value: string;
  ref?: React.Ref<HTMLButtonElement>;
};

function TabsTrigger({
  children,
  className,
  onClick,
  ref,
  value,
  ...props
}: TabsTriggerProps) {
  const ctx = useTabsContext();
  const isActive = ctx.value === value;
  const triggerId = `${ctx.baseId}-trigger-${value}`;
  const contentId = `${ctx.baseId}-content-${value}`;
  return (
    <button
      {...props}
      aria-controls={contentId}
      aria-selected={isActive}
      className={cn(
        "data-[state=active]:bg-background dark:data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow,opacity] duration-150 focus-visible:outline-none active:opacity-60 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4",
        className
      )}
      data-slot="tabs-trigger"
      data-state={isActive ? "active" : "inactive"}
      id={triggerId}
      onClick={(e) => {
        onClick?.(e);
        if (e.defaultPrevented) {
          return;
        }
        ctx.setValue(value);
      }}
      ref={ref}
      role="tab"
      tabIndex={isActive ? 0 : -1}
      type="button"
    >
      {children}
    </button>
  );
}

type TabsContentProps = Omit<React.ComponentPropsWithoutRef<"div">, "value"> & {
  value: string;
  as?: React.ElementType;
  asChild?: boolean;
  ref?: React.Ref<HTMLDivElement>;
};

function TabsContent({
  as,
  asChild,
  children,
  className,
  ref,
  value,
  ...props
}: TabsContentProps) {
  const ctx = useTabsContext();
  const isActive = ctx.value === value;
  const triggerId = `${ctx.baseId}-trigger-${value}`;
  const contentId = `${ctx.baseId}-content-${value}`;
  const merged = {
    ...props,
    "aria-hidden": !isActive,
    "aria-labelledby": triggerId,
    className: cn("flex-1 outline-none", className),
    "data-slot": "tabs-content",
    "data-state": isActive ? "active" : "inactive",
    hidden: !isActive,
    id: contentId,
    role: "tabpanel",
    tabIndex: 0,
  };
  if (asChild && React.isValidElement(children)) {
    const child = children as React.ReactElement<Record<string, unknown>>;
    return React.cloneElement(child, { ...merged, ref } as never);
  }
  const Component = (as ?? "div") as React.ElementType;
  return (
    <Component {...merged} ref={ref}>
      {children}
    </Component>
  );
}

export { Tabs, TabsContent, TabsList, TabsTrigger };

Tabs organize related content into panels that switch in place. Only one panel is visible at a time, keeping dense interfaces compact.

Installation

Usage

tabs.tsx
import {
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from "@/components/ui/tabs";
tabs.tsx
<Tabs defaultValue="account">
  <TabsList>
    <TabsTrigger value="account">Account</TabsTrigger>
    <TabsTrigger value="password">Password</TabsTrigger>
  </TabsList>
  <TabsContent value="account">Account settings.</TabsContent>
  <TabsContent value="password">Password settings.</TabsContent>
</Tabs>

Composition

Tabs
├── TabsList
│   └── TabsTrigger
└── TabsContent

Examples

Vertical

Set orientation="vertical" to stack triggers beside the panel.

Update your display name and email address.
tabs-vertical.tsx
"use client";

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

export function TabsVertical() {
  return (
    <Tabs className="w-[400px]" defaultValue="account" orientation="vertical">
      <TabsList>
        <TabsTrigger value="account">Account</TabsTrigger>
        <TabsTrigger value="password">Password</TabsTrigger>
        <TabsTrigger value="notifications">Notifications</TabsTrigger>
      </TabsList>
      <TabsContent className="text-muted-foreground text-sm" value="account">
        Update your display name and email address.
      </TabsContent>
      <TabsContent className="text-muted-foreground text-sm" value="password">
        Change your password and enable two-factor authentication.
      </TabsContent>
      <TabsContent
        className="text-muted-foreground text-sm"
        value="notifications"
      >
        Control which emails and push notifications you receive.
      </TabsContent>
    </Tabs>
  );
}

Disabled

Set disabled on a trigger to prevent selection.

tabs-disabled.tsx
"use client";

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

export function TabsDisabled() {
  return (
    <Tabs defaultValue="home">
      <TabsList>
        <TabsTrigger value="home">Home</TabsTrigger>
        <TabsTrigger disabled value="settings">
          Disabled
        </TabsTrigger>
      </TabsList>
    </Tabs>
  );
}

With icons

Triggers accept icons before the label. Icons size themselves via [&_svg]:size-4.

tabs-icons.tsx
"use client";

import { CodeIcon, FileCodeIcon } from "lucide-react";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";

export function TabsIcons() {
  return (
    <Tabs defaultValue="preview">
      <TabsList>
        <TabsTrigger value="preview">
          <CodeIcon />
          Preview
        </TabsTrigger>
        <TabsTrigger value="code">
          <FileCodeIcon />
          Code
        </TabsTrigger>
      </TabsList>
    </Tabs>
  );
}

In Context

Docs tabs

The component renders here.
tabs-docs.tsx
"use client";

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

export function TabsDocs() {
  return (
    <Tabs className="mx-auto w-full max-w-sm" defaultValue="preview">
      <TabsList className="mx-auto">
        <TabsTrigger value="preview">Preview</TabsTrigger>
        <TabsTrigger value="code">Code</TabsTrigger>
      </TabsList>
      <TabsContent
        className="text-muted-foreground pt-3 text-sm"
        value="preview"
      >
        The component renders here.
      </TabsContent>
      <TabsContent className="text-muted-foreground pt-3 text-sm" value="code">
        Source code for this example.
      </TabsContent>
    </Tabs>
  );
}

API Reference

Tabs

PropTypeDefaultDescription
defaultValuestring—Value of the tab open on first render.
valuestring—Controlled value of the open tab.
onValueChangefunction—Called when the active tab changes.
orientation
horizontalvertical
horizontalLayout axis of the tab list.

TabsList

PropTypeDefaultDescription
motionstring260 cubic-bezier(0.22, 1, 0.36, 1)Timing for the active-tab indicator slide. Set to off to disable, or pass duration + easing like 150 ease-out.

The active-tab background slides between triggers using the Web Animations API. The default is 260ms with a smooth-out curve.

tsx
<TabsList motion="400 ease-in-out">
  <TabsTrigger value="account">Account</TabsTrigger>
  <TabsTrigger value="password">Password</TabsTrigger>
</TabsList>

Set motion="off" to snap the indicator without animation. prefers-reduced-motion disables the slide automatically.

TabsTrigger

PropTypeDefaultDescription
valuestring—Identifier matching the associated TabsContent.
disabledbooleanfalsePrevent the trigger from being selected.

As Prop

TabsContent accepts as to render a custom element. TabsTrigger renders a native <button> by default.

Controlled

tsx
const [value, setValue] = React.useState("tab-1")
<Tabs value={value} onValueChange={setValue}>{/* ... */}</Tabs>

Keyboard

KeyAction
← / →Move between triggers (horizontal)
↑ / ↓Move between triggers (vertical)
Home / EndFirst / last trigger
Enter / SpaceActivate focused trigger

Data Attributes

AttributeValues
data-slottabs, tabs-list, tabs-trigger, tabs-content
data-stateactive | inactive
data-orientationhorizontal | vertical

Accessibility

  • Follows the WAI-ARIA tabs pattern.
  • Triggers expose role="tab" and aria-selected.
  • Keyboard: ArrowLeft and ArrowRight move between triggers.

Best Practices

  • Keep tabs to three or four. More tabs become a nav, not a tab list.
  • Pick a default. Empty tab groups confuse users about the current state.
  • Do not nest tabs. Nested tabs lose context; use a segmented control instead.
  • Do not lazy-load the first tab. The default tab should not flash.