//navigation
Stepper
Shows progress through a multi-step flow such as checkout or onboarding, with completed, active and upcoming steps. Copy-paste ready.
// title: Checkout steps with back and continue
"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
Stepper,
StepperDescription,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
StepperTrigger,
} from "@/components/ui/stepper";
const steps = [
{ body: "3 items · $248.00", description: "Review items", title: "Cart" },
{
body: "Maya Patel, 221 Mission St, San Francisco, CA 94105",
description: "Where it's going",
title: "Shipping",
},
{
body: "Visa ending 4242 · billing address same as shipping",
description: "Card or wallet",
title: "Payment",
},
{
body: "Arrives Thu, Oct 22. We'll email the receipt to maya@acme.dev.",
description: "Place order",
title: "Confirm",
},
];
export default function Particle() {
const [step, setStep] = useState(2);
const current = steps[step - 1];
return (
<div className="flex w-full max-w-xl flex-col gap-6">
<Stepper onValueChange={setStep} value={step}>
{steps.map((s, i) => (
<StepperItem key={s.title} step={i + 1}>
<StepperTrigger disabled={i + 1 > step}>
<StepperIndicator />
<div>
<StepperTitle>{s.title}</StepperTitle>
<StepperDescription className="max-sm:hidden">
{s.description}
</StepperDescription>
</div>
</StepperTrigger>
<StepperSeparator />
</StepperItem>
))}
</Stepper>
<div className="rounded-xl border p-4">
<p className="font-medium text-sm">
{current ? current.title : "Order placed"}
</p>
<p className="mt-1 text-muted-foreground text-sm">
{current ? current.body : "Order #4821 is confirmed. Thanks, Maya!"}
</p>
</div>
<div className="flex justify-between">
<Button
disabled={step === 1}
onClick={() => setStep((s) => s - 1)}
variant="outline"
>
Back
</Button>
<Button onClick={() => setStep((s) => (current ? s + 1 : 1))}>
{!current
? "Start over"
: step === steps.length
? "Place order"
: "Continue"}
</Button>
</div>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @cnippet/stepper
Usage
import {
Stepper,
StepperDescription,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
StepperTrigger,
} from "@/components/ui/stepper"const [step, setStep] = useState(1)
<Stepper value={step} onValueChange={setStep}>
{["Cart", "Shipping", "Payment"].map((title, i) => (
<StepperItem key={title} step={i + 1}>
<StepperTrigger>
<StepperIndicator />
<StepperTitle>{title}</StepperTitle>
</StepperTrigger>
<StepperSeparator />
</StepperItem>
))}
</Stepper>Anatomy
<Stepper> {/* <ol>; holds the active step */}
<StepperItem step={1}> {/* <li>; data-state is completed, active or inactive */}
<StepperTrigger> {/* button that makes this step active */}
<StepperIndicator /> {/* number, or a check when completed */}
<StepperTitle />
<StepperDescription />
</StepperTrigger>
<StepperSeparator /> {/* line to the next step; hidden on the last one */}
</StepperItem>
</Stepper>Good to know
- Steps start at 1. Every step before
valueshows as completed,valueis active, and later steps are upcoming. Usecompletedon aStepperItemto mark a step done out of order. - The active item gets
aria-current="step", so screen readers announce where the user is. StepperTriggeris optional. Leave it out (as in the compact example) when users shouldn't click between steps, and usedisabledon an item to block steps they haven't reached yet.- The stepper only shows progress. Render each step's content yourself, based on the same
value. - Style by state with
group-data-[state=completed]/step:and friends, since every part sits inside agroup/stepitem.
API Reference
Stepper
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | Controlled active step |
defaultValue | number | 1 | Initial active step when uncontrolled |
onValueChange | (step: number) => void | — | Called when a trigger is clicked |
orientation | "horizontal" | "vertical" | "horizontal" | Layout direction |
StepperItem
| Prop | Type | Default | Description |
|---|---|---|---|
step | number | — | This step's number, starting at 1 |
completed | boolean | — | Show as completed regardless of value |
disabled | boolean | false | Disables this step's trigger |
StepperIndicator
Shows the step number, or a check when completed. Pass children to show something else, such as an icon.
Examples
Vertical
An onboarding checklist with titles and descriptions stacked down the side.
// title: Vertical onboarding checklist
import {
Stepper,
StepperDescription,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
StepperTrigger,
} from "@/components/ui/stepper";
const steps = [
{
description: "Name it and pick a region.",
title: "Create a workspace",
},
{
description: "Point app.acme.dev at us with a CNAME record.",
title: "Connect your domain",
},
{
description: "Send invites by email or share a join link.",
title: "Invite your team",
},
{
description: "Push to main and we'll build it.",
title: "Ship your first deploy",
},
];
export default function Particle() {
return (
<div className="w-full max-w-sm rounded-xl border p-5">
<p className="font-semibold">Get started</p>
<p className="mb-5 text-muted-foreground text-sm">2 of 4 complete</p>
<Stepper defaultValue={3} orientation="vertical">
{steps.map((s, i) => (
<StepperItem key={s.title} step={i + 1}>
<StepperTrigger>
<StepperIndicator />
<div className="pt-0.5 pb-1">
<StepperTitle>{s.title}</StepperTitle>
<StepperDescription>{s.description}</StepperDescription>
</div>
</StepperTrigger>
<StepperSeparator />
</StepperItem>
))}
</Stepper>
</div>
);
}
Compact
Dots without triggers, with the current step's name and a count above.
// title: Compact dot progress with step count
"use client";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
Stepper,
StepperIndicator,
StepperItem,
StepperSeparator,
} from "@/components/ui/stepper";
const TITLES = ["Account", "Profile", "Preferences", "Review", "Done"];
export default function Particle() {
const [step, setStep] = useState(3);
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<div className="flex items-baseline justify-between text-sm">
<span className="font-medium">{TITLES[step - 1]}</span>
<span className="text-muted-foreground tabular-nums">
Step {step} of {TITLES.length}
</span>
</div>
<Stepper value={step}>
{TITLES.map((title, i) => (
<StepperItem key={title} step={i + 1}>
<StepperIndicator className="size-2.5 group-data-[state=active]/step:ring-2">
<span className="sr-only">{title}</span>
</StepperIndicator>
<StepperSeparator className="mx-1 mt-[4.5px]" />
</StepperItem>
))}
</Stepper>
<div className="flex justify-between">
<Button
disabled={step === 1}
onClick={() => setStep((s) => s - 1)}
size="sm"
variant="ghost"
>
<ChevronLeftIcon aria-hidden="true" />
Back
</Button>
<Button
disabled={step === TITLES.length}
onClick={() => setStep((s) => s + 1)}
size="sm"
variant="ghost"
>
Next
<ChevronRightIcon aria-hidden="true" />
</Button>
</div>
</div>
);
}
Revisiting finished steps
Steps the user has finished stay clickable after they go back; later steps stay disabled.
// title: Jump back to finished steps
"use client";
import { useState } from "react";
import { Badge } from "@/components/ui/badge";
import {
Stepper,
StepperIndicator,
StepperItem,
StepperSeparator,
StepperTitle,
StepperTrigger,
} from "@/components/ui/stepper";
const steps = ["Details", "Pricing", "Media", "Publish"];
export default function Particle() {
const [step, setStep] = useState(2);
// Steps the user has already finished stay reachable after going back.
const [furthest, setFurthest] = useState(3);
return (
<div className="flex w-full max-w-lg flex-col gap-5">
<Stepper
onValueChange={(next) => {
setStep(next);
setFurthest((f) => Math.max(f, next));
}}
value={step}
>
{steps.map((title, i) => (
<StepperItem
completed={i + 1 < furthest && i + 1 !== step}
disabled={i + 1 > furthest}
key={title}
step={i + 1}
>
<StepperTrigger className="flex-row gap-2">
<StepperIndicator />
<StepperTitle className="max-sm:sr-only">{title}</StepperTitle>
</StepperTrigger>
<StepperSeparator />
</StepperItem>
))}
</Stepper>
<div className="flex items-center justify-between rounded-xl border p-4 text-sm">
<span>
Editing <span className="font-medium">{steps[step - 1]}</span>
</span>
<Badge variant="outline">
{furthest - 1} of {steps.length} done
</Badge>
</div>
<p className="text-muted-foreground text-xs">
Click any finished step to jump back to it.
</p>
</div>
);
}