A frame for questionnaires and sign-up flows that show one question at a time. Every step is a <details> with a shared name, so the browser keeps exactly one step open. The summary of the open step is its title, and the summaries of its neighbours become the Back and Next buttons. While a step has an invalid field, :has(:invalid) swaps Next for a disabled button. Progress, the counter and the transitions are CSS. The base component is a Server Component with no JavaScript; the optional client version from step-wizard-client adds async validate, onComplete, onStepChange and the useStepWizard hook.
Browser Support
Groups expandable sections
Styles elements based on their contents
Colors focus rings and step buttons
Preview
This wizard is a Server Component inside a form, with no JavaScript. Next stays locked until the step is valid.
Installation
Usage
import { Textarea } from "@/components/ui/textarea"
import { Input } from "@/components/ui/input"
import { StepWizard, StepWizardStep } from "@/components/ui/step-wizard"
// Server Component, no JavaScript: Finish submits the form
export default function Survey() {
return (
<form action={saveSurvey}>
<StepWizard transition="slide">
<StepWizardStep title="How should we call you?">
<Input name="name" required minLength={2} />
</StepWizardStep>
<StepWizardStep title="Anything else?" description="Optional">
<Textarea name="note" />
</StepWizardStep>
</StepWizard>
</form>
)
}Examples
Client version
StepWizard and StepWizardStep from step-wizard-client render the same markup and add validate, onComplete and onStepChange. Switch transitions above the card and try pressing Next on the first step without picking anything.
What are you planning?
Step 1 of 4NextBack
How many people?
Step 2 of 4NextBack
How should we call you?
Step 3 of 4NextBack
All set
Step 4 of 4NextBack
import { Textarea } from "@/components/ui/textarea"
import { Input } from "@/components/ui/input"
"use client"
import { StepWizard, StepWizardStep } from "@/components/ui/step-wizard-client"
export default function Survey() {
const [name, setName] = useState("")
return (
<StepWizard transition="slide" onComplete={() => console.log("done")}>
<StepWizardStep
title="How should we call you?"
validate={() => (name.trim() ? true : "Type your name")}
>
<Input value={name} onChange={(e) => setName(e.target.value)} />
</StepWizardStep>
<StepWizardStep title="Anything else?" description="Optional">
<Textarea />
</StepWizardStep>
</StepWizard>
)
}Custom controls
Turn off the built-in buttons with showControls={false} and drive the wizard with useStepWizard(). Here a click on an option moves forward at once.
Pick a color
Step 1 of 3NextBack
Pick a size
Step 2 of 3NextBack
You picked
Step 3 of 3NextBack
import { Button } from "@/components/ui/button"
import { useStepWizard } from "@/components/ui/step-wizard-client"
function Choices({ options, onPick }) {
const { next, back, isFirst } = useStepWizard()
return (
<>
{options.map((option) => (
<Button key={option} onClick={() => { onPick(option); next() }}>
{option}
</Button>
))}
{!isFirst && <Button onClick={back}>Back</Button>}
</>
)
}
<StepWizard showControls={false}>
<StepWizardStep title="Pick a color">
<Choices options={["Sand", "Moss", "Slate"]} onPick={setColor} />
</StepWizardStep>
<StepWizardStep title="Pick a size">
<Choices options={["S", "M", "L", "XL"]} onPick={setSize} />
</StepWizardStep>
</StepWizard>Async validation
validate may return a promise. While it runs the Next button is locked. Return a string to block the step and show it as an error.
Your email
Step 1 of 2NextBack
Choose a password
Step 2 of 2NextBack
<StepWizardStep
title="Your email"
validate={async () => {
const res = await fetch(`/api/email-free?email=${email}`)
const { free } = await res.json()
return free ? true : "This email is already registered"
}}
>
<Input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
</StepWizardStep>Transitions
fade-rise, slide, scale-blur, wipe and stagger. The open step plays a CSS animation; the closing one disappears at once. With reduced motion every transition becomes a short fade.
<StepWizard transition="wipe">…</StepWizard>
<StepWizard transition="stagger">…</StepWizard>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | StepWizardStep elements, one per step |
| transition | "fade-rise" | "slide" | "scale-blur" | "wipe" | "stagger" | "fade-rise" | Animation between steps |
| defaultStep | number | 0 | Zero-based step shown on mount |
| onStepChange | (step: number) => void | - | Client version only: called with the new step index |
| onComplete | () => void | Promise<void> | - | Client version only: called after the last step passes validation, may be async. A thrown error or rejected promise is shown as the step error. Without it Finish submits the surrounding form |
| showProgress | boolean | true | Show the progress bar and the 01 / 04 counter |
| showControls | boolean | true | Render the built-in Back, Next and Finish buttons |
| labels | Partial<StepWizardLabels> | - | Texts of the buttons, the progress label and the fallback error |
| name | string | useId() | Shared name of the step <details>. Generated when omitted |
| error | string | null | - | Error under the step, for example from a server action |
| pending | boolean | false | Busy state: a spinner replaces the Next arrow |
| className | string | - | Additional CSS classes |
Components
StepWizardStep
| Prop | Type | Default | Description |
|---|---|---|---|
| title | ReactNode | - | Step heading. It is the summary of the step, so focus stays on it after Next |
| description | ReactNode | - | Text under the heading |
| validate | () => boolean | string | undefined | Promise<…> | - | Client version only: check before moving on, false or a string blocks the step |
| headingAs | "h2" | "h3" | "h4" | "h2" | Heading element of the title |
| className | string | - | Additional CSS classes |
useStepWizard
Comes from step-wizard-client. Returns the wizard state and actions and works in any component inside the client StepWizard.
| Value | Type | Description |
|---|---|---|
| step | number | Zero-based index of the current step |
| total | number | Number of steps |
| isFirst | boolean | The current step is the first one |
| isLast | boolean | The current step is the last one |
| progress | number | Progress from 0 to 100 |
| pending | boolean | Validation or onComplete is running |
| error | string | null | Message returned by validate |
| next | () => Promise<void> | Validate the step and move forward, or complete on the last step |
| back | () => void | Go one step back |
| goTo | (step: number) => void | Jump to a step without validation |
| setError | (error: string | null) => void | Show or clear an error message |