# Shadcn Stepper

A multi step navigation for checkouts, onboarding and long forms. It shows where the user is, which steps are done and what comes next. Steps can be horizontal or vertical, locked in order with `linear`, and marked as loading, invalid or disabled. Each step is a real button with arrow key navigation, and the step content and Back and Next buttons connect to it without extra state.

`stepper-demo.tsx`:

```tsx
import { CheckIcon } from "lucide-react";
import {
  Stepper,
  StepperContent,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperNext,
  StepperPanel,
  StepperPrevious,
  StepperSeparator,
  StepperTitle,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = ["Account", "Profile", "Review"];

export default function StepperDemo() {
  return (
    <Stepper
      defaultValue={2}
      indicators={{ completed: <CheckIcon className="size-3.5" /> }}
      className="max-w-md space-y-6"
    >
      <StepperNav>
        {steps.map((title, index) => (
          <StepperItem key={title} step={index + 1}>
            <StepperTrigger>
              <StepperIndicator>{index + 1}</StepperIndicator>
              <StepperTitle>{title}</StepperTitle>
            </StepperTrigger>
            {index < steps.length - 1 && (
              <StepperSeparator className="mx-2.5 group-data-[state=completed]/step:bg-primary" />
            )}
          </StepperItem>
        ))}
      </StepperNav>
      <StepperPanel className="rounded-lg border p-6 text-center text-sm text-muted-foreground">
        {steps.map((title, index) => (
          <StepperContent key={title} value={index + 1}>
            {title} step content
          </StepperContent>
        ))}
      </StepperPanel>
      <div className="flex justify-between">
        <StepperPrevious />
        <StepperNext />
      </div>
    </Stepper>
  );
}
```

## Installation

```bash
npx shadcn@latest add @shadcnuikit/stepper1
```

This adds `components/ui/stepper.tsx`, the `button` component it depends on, and a demo file. Set up the registry once as described in [Shadcn CLI](https://shadcnuikit.com/docs/shadcn-cli). Stepper is free and installs without an API key.

### Manual installation

Install the dependencies and the `button` component:

```bash
npm install @ui-sdk/core@beta @ui-sdk/react@beta lucide-react
npx shadcn@latest add button
```

Copy the source into `components/ui/stepper.tsx`:

`components/ui/stepper.tsx`:

```tsx
"use client";

import * as React from "react";
import {
  createChange,
  createRovingFocus,
  definePrimitive,
  idPart,
  keepFocus,
  type ChangeDetails,
} from "@ui-sdk/core";
import { createParts } from "@ui-sdk/react/primitive";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";

import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";

type StepperOrientation = "horizontal" | "vertical";
type StepState = "active" | "completed" | "inactive";
type StepIndicators = {
  active?: React.ReactNode;
  completed?: React.ReactNode;
  inactive?: React.ReactNode;
  loading?: React.ReactNode;
  invalid?: React.ReactNode;
};

// "next-press" and "previous-press" aren't in the shared vocabulary.
type StepperReason = "item-press" | "next-press" | "previous-press" | "imperative";

type StepperOptions = {
  value?: number;
  defaultValue?: number;
  onValueChange?: (value: number, details: ChangeDetails<StepperReason>) => void;
  orientation?: StepperOrientation;
  linear?: boolean;
};

type StepperState = {
  value: number;
  orientation: StepperOrientation;
  linear: boolean;
  focused: string | null;
  steps: number[];
  reached: number;
};

type StepFlags = {
  completed?: boolean;
  disabled?: boolean;
  loading?: boolean;
  invalid?: boolean;
};

type StepProps = StepFlags & { value: string };

type StepPartState = {
  state: StepState;
  loading: boolean;
  invalid: boolean;
  disabled: boolean;
};

function stepState(state: StepperState, step: number, flags: StepFlags): StepState {
  if (flags.completed || step < state.value) return "completed";
  return step === state.value ? "active" : "inactive";
}

function nextStep(state: StepperState) {
  return state.steps.find((step) => step > state.value) ?? state.value + 1;
}

function previousStep(state: StepperState) {
  return state.steps.findLast((step) => step < state.value) ?? state.value - 1;
}

function canNext(state: StepperState) {
  return state.steps.length === 0 || state.value < state.steps[state.steps.length - 1];
}

function canPrevious(state: StepperState) {
  return state.steps.length === 0 ? state.value > 1 : state.value > state.steps[0];
}

function reachable(state: StepperState, step: number, flags: StepFlags) {
  if (flags.disabled) return false;
  if (!state.linear) return true;
  return step <= Math.max(state.value, state.reached) || !!flags.completed || step === nextStep(state);
}

function partState(state: StepperState, props: StepProps): StepPartState {
  const step = Number(props.value);
  return {
    state: stepState(state, step, props),
    loading: !!props.loading && step === state.value,
    invalid: !!props.invalid,
    disabled: !reachable(state, step, props),
  };
}

function stepAttrs(state: StepperState, props: StepProps) {
  const current = partState(state, props);
  return {
    "data-state": current.state,
    "data-loading": current.loading ? "" : undefined,
    "data-invalid": current.invalid ? "" : undefined,
    "data-disabled": current.disabled ? "" : undefined,
  };
}

const inherited = {
  value: { kind: "string", from: "item", required: true },
  completed: { kind: "boolean", from: "item" },
  disabled: { kind: "boolean", from: "item" },
  loading: { kind: "boolean", from: "item" },
  invalid: { kind: "boolean", from: "item" },
} as const;

const stepper = definePrimitive({
  name: "stepper",
  options: {
    value: "number",
    defaultValue: "number",
    onValueChange: "callback",
    orientation: "string",
    linear: "boolean",
  },
  controlled: ["value"],
  state: (options: StepperOptions): StepperState => ({
    value: options.value ?? options.defaultValue ?? 1,
    orientation: options.orientation ?? "horizontal",
    linear: options.linear ?? false,
    focused: null,
    steps: [],
    reached: options.value ?? options.defaultValue ?? 1,
  }),
  sync: (options) => ({
    ...(options.value === undefined ? {} : { value: options.value }),
    orientation: options.orientation ?? "horizontal",
    linear: options.linear ?? false,
  }),
  api: (context) => {
    const change = createChange(context);
    context.onDestroy(
      context.store.subscribe(() => {
        const { value, reached } = context.store.get();
        if (value > reached) context.store.set({ reached: value });
      }),
    );
    const roving = createRovingFocus<StepperState, StepProps>(context, {
      slot: "trigger",
      key: "focused",
      remember: false,
      orientation: () => "both",
      loop: () => true,
      disabled: (item) =>
        !reachable(context.store.get(), Number(item.props.value), item.props),
      preferred: (item) => Number(item.key) === context.store.get().value,
      claims: (state, item) => Number(item.key) === state.value,
    });

    const go = (step: number, reason: StepperReason, event?: Event) => {
      const changed = change("value", step, { reason, event });
      const root = context.element("root");
      if (changed && root?.contains(root.ownerDocument.activeElement)) {
        // Next and Back often live inside the step's content, which unmounts with it.
        keepFocus(() => context.element("trigger", String(context.store.get().value)) ?? undefined);
      }
      return changed;
    };

    return {
      roving,
      register(step: number) {
        const { steps } = context.store.get();
        if (steps.includes(step)) return;
        context.store.set({ steps: [...steps, step].sort((a, b) => a - b) });
      },
      unregister(step: number) {
        const { steps } = context.store.get();
        context.store.set({ steps: steps.filter((item) => item !== step) });
      },
      select(step: number, event?: Event) {
        const flags = context.props<StepProps>("trigger", String(step)) ?? {
          value: String(step),
        };
        if (!reachable(context.store.get(), step, flags)) return false;
        return go(step, event ? "item-press" : "imperative", event);
      },
      next(event?: Event) {
        const state = context.store.get();
        if (!canNext(state)) return false;
        return go(nextStep(state), event ? "next-press" : "imperative", event);
      },
      previous(event?: Event) {
        const state = context.store.get();
        if (!canPrevious(state)) return false;
        return go(previousStep(state), event ? "previous-press" : "imperative", event);
      },
    };
  },
  slots: (slot) => ({
    root: slot({
      attrs: (state) => ({
        "data-orientation": state.orientation,
        "data-linear": state.linear ? "" : undefined,
      }),
    }),
    nav: slot({
      role: "list",
      attrs: (state) => ({
        "data-orientation": state.orientation,
        "data-state": String(state.value),
      }),
    }),
    item: slot<StepProps, StepPartState>({
      role: "listitem",
      props: {
        value: "string",
        completed: "boolean",
        disabled: "boolean",
        loading: "boolean",
        invalid: "boolean",
      },
      state: (state, part) => partState(state, part.props),
      attrs: (state, part) => stepAttrs(state, part.props),
      bind: (_el, part) => {
        const step = Number(part.key);
        part.api.register(step);
        return () => part.api.unregister(step);
      },
    }),
    trigger: slot<StepProps, StepPartState>({
      role: "button",
      focus: "roving",
      props: inherited,
      state: (state, part) => partState(state, part.props),
      attrs: (state, part) => {
        const step = Number(part.key);
        const current = partState(state, part.props);
        return {
          type: "button",
          id: `${part.id}-trigger-${idPart(part.key)}`,
          "aria-current": step === state.value ? "step" : undefined,
          "aria-disabled": current.disabled ? "true" : undefined,
          tabindex: part.api.roving.tabIndex(state, part),
          ...stepAttrs(state, part.props),
        };
      },
      press: ({ api, key }, event) => {
        api.select(Number(key), event);
      },
      on: {
        keydown: (event, { el, api }) => {
          if (el) api.roving.keydown(event as KeyboardEvent, el);
        },
      },
      bind: (el, part) => part.api.roving.bind(el, part),
    }),
    indicator: slot<StepProps, StepPartState>({
      props: inherited,
      state: (state, part) => partState(state, part.props),
      attrs: (state, part) => ({
        "aria-hidden": "true",
        ...stepAttrs(state, part.props),
      }),
    }),
    separator: slot<StepProps>({
      props: inherited,
      attrs: (state, part) => ({
        "aria-hidden": "true",
        ...stepAttrs(state, part.props),
      }),
    }),
    title: slot<StepProps>({
      props: inherited,
      attrs: (state, part) => stepAttrs(state, part.props),
    }),
    description: slot<StepProps>({
      props: inherited,
      attrs: (state, part) => stepAttrs(state, part.props),
    }),
    panel: slot({
      attrs: (state) => ({ "data-state": String(state.value) }),
    }),
    content: slot<{ value: string; forceMount?: boolean }>({
      props: { value: "string", forceMount: "boolean" },
      present: (state, part) => !!part.props.forceMount || Number(part.key) === state.value,
      attrs: (state, part) => {
        const active = Number(part.key) === state.value;
        return {
          "data-state": active ? "active" : "inactive",
          hidden: active ? undefined : "",
        };
      },
    }),
    previous: slot({
      role: "button",
      focus: "native",
      attrs: (state) => ({
        type: "button",
        "aria-disabled": canPrevious(state) ? undefined : "true",
      }),
      press: ({ api }, event) => {
        api.previous(event);
      },
    }),
    next: slot({
      role: "button",
      focus: "native",
      attrs: (state) => ({
        type: "button",
        "aria-disabled": canNext(state) ? undefined : "true",
      }),
      press: ({ api }, event) => {
        api.next(event);
      },
    }),
  }),
  agent: { actions: ["select", "next", "previous"] },
});

const Parts = createParts(stepper, {
  root: "div",
  nav: "ol",
  item: "li",
  trigger: "button",
  indicator: "span",
  separator: "span",
  title: "span",
  description: "span",
  panel: "div",
  content: "div",
  previous: "button",
  next: "button",
});

const StepperIndicatorsContext = React.createContext<StepIndicators>({});

type PartClassName<T> = Omit<
  React.ComponentProps<T extends React.ElementType ? T : never>,
  "className"
> & {
  className?: string;
};

// A step's value and flags reach these parts from the StepperItem around them.
type StepPartProps<T> = Omit<PartClassName<T>, keyof StepProps>;

type StepperProps = StepperOptions &
  Omit<PartClassName<typeof Parts.Root>, keyof StepperOptions> & {
    indicators?: StepIndicators;
  };

function Stepper({ indicators, className, ...props }: StepperProps) {
  const stable = React.useMemo(() => indicators ?? {}, [indicators]);
  return (
    <StepperIndicatorsContext.Provider value={stable}>
      <Parts.Root
        data-slot="stepper"
        className={cn("group/stepper w-full", className)}
        {...props}
      />
    </StepperIndicatorsContext.Provider>
  );
}

function StepperNav({ className, ...props }: PartClassName<typeof Parts.Nav>) {
  return (
    <Parts.Nav
      className={cn(
        "group/stepper-nav inline-flex data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex-col",
        className,
      )}
      {...props}
    />
  );
}

type StepperItemProps = Omit<PartClassName<typeof Parts.Item>, keyof StepProps> &
  StepFlags & { step: number };

function StepperItem({ step, className, ...props }: StepperItemProps) {
  return (
    <Parts.Item
      value={String(step)}
      className={cn(
        "group/step flex items-center justify-center not-last:flex-1 group-data-[orientation=horizontal]/stepper-nav:flex-row group-data-[orientation=vertical]/stepper-nav:flex-col",
        className,
      )}
      {...props}
    />
  );
}

const statusText: Record<StepState, string> = {
  active: "current step",
  completed: "completed",
  inactive: "not started",
};

type StepperTriggerProps = StepPartProps<typeof Parts.Trigger>;

function StepperTrigger({ className, children, ...props }: StepperTriggerProps) {
  return (
    <Parts.Trigger
      className={cn(
        "inline-flex cursor-pointer items-center gap-2.5 rounded-full outline-none focus-visible:z-10 focus-visible:ring-3 focus-visible:ring-ring/50 aria-disabled:cursor-not-allowed aria-disabled:opacity-60",
        className,
      )}
      {...(props as PartClassName<typeof Parts.Trigger>)}
    >
      {(step: StepPartState) => (
        <>
          {typeof children === "function" ? children(step) : children}
          <span className="sr-only">
            {", "}
            {step.invalid ? "has an error" : step.loading ? "in progress" : statusText[step.state]}
          </span>
        </>
      )}
    </Parts.Trigger>
  );
}

function StepperIndicator({
  className,
  children,
  ...props
}: StepPartProps<typeof Parts.Indicator>) {
  const indicators = React.useContext(StepperIndicatorsContext);
  return (
    <Parts.Indicator
      className={cn(
        "relative flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted text-xs font-medium text-muted-foreground data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=completed]:bg-primary data-[state=completed]:text-primary-foreground data-invalid:data-state:bg-destructive/10 data-invalid:data-state:text-destructive",
        className,
      )}
      {...(props as PartClassName<typeof Parts.Indicator>)}
    >
      {(step: StepPartState) => (
        <span className="absolute flex items-center justify-center">
          {(step.loading && indicators.loading) ||
            (step.invalid && indicators.invalid) ||
            indicators[step.state] ||
            (typeof children === "function" ? children(step) : children)}
        </span>
      )}
    </Parts.Indicator>
  );
}

function StepperSeparator({ className, ...props }: StepPartProps<typeof Parts.Separator>) {
  return (
    <Parts.Separator
      className={cn(
        "m-0.5 rounded-full bg-muted group-data-[orientation=horizontal]/stepper-nav:h-0.5 group-data-[orientation=horizontal]/stepper-nav:flex-1 group-data-[orientation=vertical]/stepper-nav:h-12 group-data-[orientation=vertical]/stepper-nav:w-0.5",
        className,
      )}
      {...(props as PartClassName<typeof Parts.Separator>)}
    />
  );
}

function StepperTitle({ className, ...props }: StepPartProps<typeof Parts.Title>) {
  return (
    <Parts.Title
      className={cn("block text-sm leading-none font-medium", className)}
      {...(props as PartClassName<typeof Parts.Title>)}
    />
  );
}

function StepperDescription({
  className,
  ...props
}: StepPartProps<typeof Parts.Description>) {
  return (
    <Parts.Description
      className={cn("block text-sm text-muted-foreground", className)}
      {...(props as PartClassName<typeof Parts.Description>)}
    />
  );
}

function StepperPanel({ className, ...props }: PartClassName<typeof Parts.Panel>) {
  return <Parts.Panel className={cn("w-full", className)} {...props} />;
}

type StepperContentProps = Omit<PartClassName<typeof Parts.Content>, "value"> & {
  value: number;
};

function StepperContent({ value, className, ...props }: StepperContentProps) {
  return <Parts.Content value={String(value)} className={cn("w-full", className)} {...props} />;
}

type StepperButtonProps<T> = PartClassName<T> &
  Pick<React.ComponentProps<typeof Button>, "variant" | "size">;

function StepperPrevious({
  className,
  children,
  variant = "outline",
  size,
  ...props
}: StepperButtonProps<typeof Parts.Previous>) {
  return (
    <Parts.Previous
      render={<Button variant={variant} size={size} />}
      className={cn("aria-disabled:pointer-events-none aria-disabled:opacity-50", className)}
      {...props}
    >
      {children ?? (
        <>
          <ChevronLeftIcon aria-hidden="true" className="rtl:rotate-180" />
          Back
        </>
      )}
    </Parts.Previous>
  );
}

function StepperNext({
  className,
  children,
  variant,
  size,
  ...props
}: StepperButtonProps<typeof Parts.Next>) {
  return (
    <Parts.Next
      render={<Button variant={variant} size={size} />}
      className={cn("aria-disabled:pointer-events-none aria-disabled:opacity-50", className)}
      {...props}
    >
      {children ?? (
        <>
          Next
          <ChevronRightIcon aria-hidden="true" className="rtl:rotate-180" />
        </>
      )}
    </Parts.Next>
  );
}

export {
  Stepper,
  StepperContent,
  StepperDescription,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperNext,
  StepperPanel,
  StepperPrevious,
  StepperSeparator,
  StepperTitle,
  StepperTrigger,
  stepper,
  type StepIndicators,
  type StepperContentProps,
  type StepperItemProps,
  type StepperOptions,
  type StepperProps,
  type StepperReason,
  type StepperTriggerProps,
};
```

## Usage

```tsx
import {
  Stepper,
  StepperContent,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperNext,
  StepperPanel,
  StepperPrevious,
  StepperSeparator,
  StepperTitle,
  StepperTrigger,
} from "@/components/ui/stepper";
```

```tsx
<Stepper defaultValue={1}>
  <StepperNav>
    <StepperItem step={1}>
      <StepperTrigger>
        <StepperIndicator>1</StepperIndicator>
        <StepperTitle>Account</StepperTitle>
      </StepperTrigger>
      <StepperSeparator />
    </StepperItem>
    <StepperItem step={2}>
      <StepperTrigger>
        <StepperIndicator>2</StepperIndicator>
        <StepperTitle>Review</StepperTitle>
      </StepperTrigger>
    </StepperItem>
  </StepperNav>
  <StepperPanel>
    <StepperContent value={1}>Account form</StepperContent>
    <StepperContent value={2}>Review screen</StepperContent>
  </StepperPanel>
  <StepperPrevious />
  <StepperNext />
</Stepper>
```

Steps are numbered from 1. `StepperItem` takes the step number in `step`, and `StepperContent` takes the same number in `value`. Only the active step's content is rendered.

### Controlled

```tsx
const [step, setStep] = React.useState(1);

<Stepper value={step} onValueChange={setStep}>
  ...
</Stepper>;
```

`onValueChange` receives the new step and `details`. `details.reason` is `"item-press"`, `"next-press"`, `"previous-press"` or `"imperative"`, and `details.cancel()` keeps the current step, for example while a form step is invalid.

### Separator color

`StepperSeparator` is `bg-muted` by default. Color the lines of finished steps from the step's state:

```tsx
<StepperSeparator className="group-data-[state=completed]/step:bg-primary" />
```

## Examples

### Orientation

`orientation="vertical"` stacks the steps. Pair it with `StepperDescription` for a timeline style list.

`stepper-orientation.tsx`:

```tsx
import {
  Stepper,
  StepperDescription,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperSeparator,
  StepperTitle,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = [
  { title: "Order placed", description: "We received your order" },
  { title: "Shipped", description: "On its way to you" },
  { title: "Delivered", description: "Left at your door" },
];

export default function StepperOrientation() {
  return (
    <Stepper defaultValue={2} orientation="vertical" className="w-auto">
      <StepperNav>
        {steps.map((step, index) => (
          <StepperItem key={step.title} step={index + 1} className="items-start">
            <StepperTrigger className="items-start rounded-md">
              <StepperIndicator>{index + 1}</StepperIndicator>
              <span className="flex flex-col gap-1.5 text-start">
                <StepperTitle>{step.title}</StepperTitle>
                <StepperDescription>{step.description}</StepperDescription>
              </span>
            </StepperTrigger>
            {index < steps.length - 1 && (
              <StepperSeparator className="ms-2.5 h-8 group-data-[state=completed]/step:bg-primary" />
            )}
          </StepperItem>
        ))}
      </StepperNav>
    </Stepper>
  );
}
```

### Indicators

`indicators` replaces the number inside `StepperIndicator` by state: `completed`, `active`, `inactive`, `loading` and `invalid`. Here step 3 is `loading`.

`stepper-indicators.tsx`:

```tsx
import { CheckIcon, LoaderCircleIcon, XIcon } from "lucide-react";
import {
  Stepper,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperSeparator,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = [1, 2, 3, 4];

export default function StepperIndicators() {
  return (
    <Stepper
      defaultValue={3}
      indicators={{
        completed: <CheckIcon className="size-3.5" />,
        loading: <LoaderCircleIcon className="size-3.5 animate-spin" />,
        invalid: <XIcon className="size-3.5" />,
      }}
      className="max-w-sm"
    >
      <StepperNav>
        {steps.map((step) => (
          <StepperItem key={step} step={step} loading={step === 3}>
            <StepperTrigger>
              <StepperIndicator>{step}</StepperIndicator>
            </StepperTrigger>
            {step < steps.length && (
              <StepperSeparator className="group-data-[state=completed]/step:bg-primary" />
            )}
          </StepperItem>
        ))}
      </StepperNav>
    </Stepper>
  );
}
```

### Invalid

`invalid` on a `StepperItem` marks the step with an error. The indicator turns destructive and the `invalid` indicator shows.

`stepper-invalid.tsx`:

```tsx
import { CheckIcon, XIcon } from "lucide-react";
import {
  Stepper,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperSeparator,
  StepperTitle,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = ["Details", "Payment", "Confirm"];

export default function StepperInvalid() {
  return (
    <Stepper
      defaultValue={2}
      indicators={{
        completed: <CheckIcon className="size-3.5" />,
        invalid: <XIcon className="size-3.5" />,
      }}
      className="max-w-md"
    >
      <StepperNav>
        {steps.map((title, index) => (
          <StepperItem key={title} step={index + 1} invalid={index === 1}>
            <StepperTrigger>
              <StepperIndicator>{index + 1}</StepperIndicator>
              <StepperTitle className="group-data-invalid/step:text-destructive">{title}</StepperTitle>
            </StepperTrigger>
            {index < steps.length - 1 && (
              <StepperSeparator className="mx-2.5 group-data-[state=completed]/step:bg-primary" />
            )}
          </StepperItem>
        ))}
      </StepperNav>
    </Stepper>
  );
}
```

### Linear

With `linear`, users can go back to any step they already reached and forward only to the next one. Steps further ahead are skipped by the keyboard and can't be pressed.

`stepper-linear.tsx`:

```tsx
import {
  Stepper,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperNext,
  StepperPrevious,
  StepperSeparator,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = [1, 2, 3, 4];

export default function StepperLinear() {
  return (
    <Stepper linear className="max-w-sm space-y-6">
      <StepperNav>
        {steps.map((step) => (
          <StepperItem key={step} step={step}>
            <StepperTrigger>
              <StepperIndicator>{step}</StepperIndicator>
            </StepperTrigger>
            {step < steps.length && (
              <StepperSeparator className="group-data-[state=completed]/step:bg-primary" />
            )}
          </StepperItem>
        ))}
      </StepperNav>
      <div className="flex justify-between">
        <StepperPrevious size="sm" />
        <StepperNext size="sm" />
      </div>
    </Stepper>
  );
}
```

### Disabled

`disabled` on a `StepperItem` locks that step.

`stepper-disabled.tsx`:

```tsx
import {
  Stepper,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperSeparator,
  StepperTitle,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = ["Plan", "Team", "Billing"];

export default function StepperDisabled() {
  return (
    <Stepper className="max-w-md">
      <StepperNav>
        {steps.map((title, index) => (
          <StepperItem key={title} step={index + 1} disabled={index === 2}>
            <StepperTrigger>
              <StepperIndicator>{index + 1}</StepperIndicator>
              <StepperTitle>{title}</StepperTitle>
            </StepperTrigger>
            {index < steps.length - 1 && <StepperSeparator className="mx-2.5" />}
          </StepperItem>
        ))}
      </StepperNav>
    </Stepper>
  );
}
```

### Controlled

Pass `value` and `onValueChange` to read and set the step from your own state.

`stepper-controlled.tsx`:

```tsx
"use client";

import * as React from "react";
import {
  Stepper,
  StepperIndicator,
  StepperItem,
  StepperNav,
  StepperSeparator,
  StepperTrigger,
} from "@/components/ui/stepper";

const steps = [1, 2, 3, 4];

export default function StepperControlled() {
  const [step, setStep] = React.useState(2);

  return (
    <div className="flex w-full max-w-sm flex-col items-center gap-4">
      <Stepper value={step} onValueChange={setStep}>
        <StepperNav>
          {steps.map((item) => (
            <StepperItem key={item} step={item}>
              <StepperTrigger>
                <StepperIndicator>{item}</StepperIndicator>
              </StepperTrigger>
              {item < steps.length && (
                <StepperSeparator className="group-data-[state=completed]/step:bg-primary" />
              )}
            </StepperItem>
          ))}
        </StepperNav>
      </Stepper>
      <p className="text-sm text-muted-foreground">
        Step {step} of {steps.length}
      </p>
    </div>
  );
}
```

More layouts built with Stepper, such as progress bars, icon cards and multi step forms, are on the [Stepper components](https://shadcnuikit.com/components/stepper) page.

## API Reference

### Stepper

The root. Holds the current step and connects every part inside it.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` | | The current step. Pass it to control the stepper. |
| `defaultValue` | `number` | `1` | The step at first, when uncontrolled. |
| `onValueChange` | `(value, details) => void` | | Runs when the step changes. `details.reason` says why, `details.cancel()` stops it. |
| `orientation` | `"horizontal"`, `"vertical"` | `"horizontal"` | Lays the steps out in a row or a column. |
| `linear` | `boolean` | `false` | Allows only steps already reached, the next step and steps marked `completed`. |
| `indicators` | `StepIndicators` | | Content for `StepperIndicator` by state: `active`, `completed`, `inactive`, `loading`, `invalid`. |
| `className` | `string` | | Classes for the root. |

The root has `data-orientation` and `data-linear` attributes for styling.

### StepperNav

The list of steps, an `ol`. Renders as a row or a column from `orientation`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | | Classes for the list. |

### StepperItem

One step, an `li`. Its number and flags reach the trigger, indicator, title, description and separator inside it.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `step` | `number` | | The step number, from 1. Required. |
| `completed` | `boolean` | `false` | Marks the step completed even when it comes after the current step. A completed step is always reachable. |
| `disabled` | `boolean` | `false` | Locks the step. It can't be pressed and arrow keys skip it. |
| `loading` | `boolean` | `false` | Marks the step as loading while it is the current step. Shows the `loading` indicator. |
| `invalid` | `boolean` | `false` | Marks the step with an error. Shows the `invalid` indicator. |
| `className` | `string` | | Classes for the step. |

Every part inside a step has `data-state` set to `active`, `completed` or `inactive`, plus `data-loading`, `data-invalid` and `data-disabled` when they apply. Style children from the step with `group-data-[state=completed]/step:`.

### StepperTrigger

The button that moves to its step. Put the indicator and title inside it.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode`, `(state) => ReactNode` | | The content. A function receives `state`, `loading`, `invalid` and `disabled`. |
| `className` | `string` | | Classes for the button. |

The trigger adds a visually hidden status, such as "completed" or "current step", after its content.

### StepperIndicator

The circle with the step number or icon.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode`, `(state) => ReactNode` | | Shown when `indicators` has nothing for the current state. |
| `className` | `string` | | Classes for the circle. |

### StepperSeparator

The line after a step. Leave it out of the last step.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | | Classes for the line. |

### StepperTitle and StepperDescription

The step's name and a short line under it.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | | Classes for the text. |

### StepperPanel

Wraps the step contents.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | | Classes for the panel. |

### StepperContent

The content for one step. Only the current step's content is rendered.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` | | The step this content belongs to. Required. |
| `forceMount` | `boolean` | `false` | Keeps the content in the page, hidden, while its step is not active. Useful to keep form state. |
| `className` | `string` | | Classes for the content. |

### StepperPrevious and StepperNext

Buttons that move one step back or forward. They render the shadcn/ui `Button` and get `aria-disabled` at the first and last step.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `Button` variant | `"outline"` for Previous, `"default"` for Next | The button style. |
| `size` | `Button` size | `"default"` | The button size. |
| `children` | `ReactNode` | `Back`, `Next` with a chevron | The button content. |
| `className` | `string` | | Classes for the button. |

## Keyboard

| Key | Action |
| --- | --- |
| `Tab` | Moves focus to the current step's trigger, then out of the list. |
| `ArrowRight`, `ArrowDown` | Moves focus to the next reachable step. Wraps to the first. |
| `ArrowLeft`, `ArrowUp` | Moves focus to the previous reachable step. Wraps to the last. |
| `Home`, `End` | Moves focus to the first or last reachable step. |
| `Enter`, `Space` | Goes to the focused step. |

Arrow keys move focus only. The step changes when a trigger is pressed. Unreachable steps, disabled or locked by `linear`, are skipped.

## Accessibility

- The nav is an ordered list and every step is a list item, so screen readers announce the step count.
- The current step's trigger has `aria-current="step"`. Each trigger reads its status after the title, such as "completed", "not started", "in progress" or "has an error".
- Unreachable steps get `aria-disabled="true"` and stay out of the arrow key order.
- When Next or Back unmounts the content that held focus, focus moves to the new step's trigger.
- The indicator and separator are `aria-hidden`. Put a `StepperTitle` in each trigger, or an `aria-label` when the trigger only has a number.

## For AI Agents

**When to use**

- A task split into ordered steps: checkout, onboarding, account setup, multi step forms.
- Showing progress through a fixed process, such as order tracking, with `orientation="vertical"`.
- Any flow where users need to see which steps are done and which are left.

**When not to use**

- Switching between independent views with no order. Use [Tabs](https://shadcnuikit.com/components/tabs) instead.
- A single progress value with no named steps. Use a [Progress](https://shadcnuikit.com/components/progress) bar.
- Showing a page's place in a hierarchy. Use a [Breadcrumb](https://shadcnuikit.com/components/breadcrumb).

**Agent notes**

- Import from `@/components/ui/stepper`. The exports are `Stepper`, `StepperNav`, `StepperItem`, `StepperTrigger`, `StepperIndicator`, `StepperSeparator`, `StepperTitle`, `StepperDescription`, `StepperPanel`, `StepperContent`, `StepperPrevious`, `StepperNext` and the `stepper` primitive.
- Steps are numbers starting at 1, not strings. `StepperItem` uses `step`, `StepperContent` uses `value`.
- To block Next until a form step is valid, call `details.cancel()` in `onValueChange` when the reason is `"next-press"`, or set `invalid` on the step.
- `StepperSeparator` does not color itself for completed steps. Add `group-data-[state=completed]/step:bg-primary`.
- Don't add click handlers to triggers or wire Back and Next yourself. `StepperPrevious` and `StepperNext` already move the step.

**Resources**

- Markdown: [/docs/components/stepper.md](https://shadcnuikit.com/docs/components/stepper.md)
- Variants: [Stepper components](https://shadcnuikit.com/components/stepper), 23 free examples
- Install: `npx shadcn@latest add @shadcnuikit/stepper1`
- MCP: call `get_item_code` with `stepper1` from the [MCP Server](https://shadcnuikit.com/docs/mcp-server)
- Full index for agents: [llms.txt](https://shadcnuikit.com/llms.txt)

Source: https://shadcnuikit.com/docs/components/stepper
More from Shadcn UI Kit: [llms.txt](https://shadcnuikit.com/llms.txt)