Interactive Example · Transitions
Transition between steps of a flow
Moving forward slides the next step in from the right and going back brings the previous one in from the left, so the motion shows where you are.
Written by Inspireca Design (drafted with AI assistance)Updated Not yet reviewed by an editor
Try it
Use it with a mouse, by touch or with the keyboard. The controls below show its other states.
Step 1 of 3
Your details
Name and email, so we can send the receipt.
How it works
In a flow with several steps, the transition can carry information: which way you just went. That is the whole reason to animate it.
What moves
The new step slides 24 pixels sideways into place while it fades in. Going forward it comes from the right; going back, from the left. Use the controls to compare a plain fade, and to try 150, 250 and 400 milliseconds.
Choosing the duration
Try all three. At 150 ms the direction is easy to miss. At 400 ms you begin to wait for it, and in a five-step flow that wait is repeated five times. Around 250 ms is a common middle ground for a panel of this size; larger areas can take a little longer, small ones less.
Short distance, not full width
The step moves 24 pixels, not the width of the screen. A short move with a fade reads as "next" just as clearly, finishes sooner, and is far less likely to bother people who are sensitive to large movements.
Where it fits
Sign-up, checkout and onboarding flows, where there is a clear forward and back. The onboarding planning skill helps decide what the steps should be before you animate between them.
Accessibility notes
- Focus follows the content. After moving, focus is placed on the new step's heading, so a screen reader reads it and the next Tab press continues from the right place.
- Position announced: "Step 2 of 3" is in a polite live region.
- Buttons that cannot be used are disabled, not hidden, so the layout does not change between steps.
- Reduced motion: the step is replaced at once, with no slide or fade. WCAG 2.2 (2.3.3 Animation from Interactions, level AAA) asks that motion triggered by interaction can be switched off; following the device setting does that.
The code
This is the source of the preview above: React with Tailwind CSS classes (step-transition.tsx). Colour names such as bg-primary and the ex- animation classes come from this site’s own stylesheet; replace them with your own.
"use client";
import { useRef, useState } from "react";
import type { DemoProps } from "@/lib/examples/keys";
const STEPS = [
{ title: "Your details", text: "Name and email, so we can send the receipt." },
{ title: "Delivery", text: "Where should the order go, and when?" },
{ title: "Review", text: "Check everything before you pay." },
];
/**
* Moving between steps of a flow. The new step slides in from the side you are heading
* towards (forward from the right, back from the left), which tells you where you are.
* Focus moves to the new heading so keyboard and screen reader users follow along.
*/
export default function StepTransition({ values }: DemoProps) {
const [step, setStep] = useState(0);
const [direction, setDirection] = useState<"forward" | "back">("forward");
const heading = useRef<HTMLHeadingElement>(null);
const fadeOnly = values.style === "fade";
const move = (to: number) => {
setDirection(to > step ? "forward" : "back");
setStep(to);
requestAnimationFrame(() => heading.current?.focus());
};
const enter = fadeOnly ? "ex-fade-in" : direction === "forward" ? "ex-enter-from-right" : "ex-enter-from-left";
return (
<div className="w-full max-w-sm text-left">
<p className="text-sm text-muted-foreground" aria-live="polite">Step {step + 1} of {STEPS.length}</p>
<div className="mt-3 overflow-hidden rounded-2xl border border-border bg-background">
{/* The key makes React create a new element for each step, which replays the entry animation. */}
<div key={step} style={{ animationDuration: `${Number(values.speed) || 250}ms` }} className={`min-h-28 p-5 ${enter}`}>
<h3 ref={heading} tabIndex={-1} className="text-lg font-semibold outline-none">{STEPS[step].title}</h3>
<p className="mt-2 text-sm text-muted-foreground">{STEPS[step].text}</p>
</div>
</div>
<div className="mt-4 flex justify-between gap-3">
<button type="button" disabled={step === 0} onClick={() => move(step - 1)}
className="h-11 rounded-[10px] border border-border-strong px-5 text-sm font-medium hover:bg-surface disabled:cursor-not-allowed disabled:opacity-45">Back</button>
<button type="button" disabled={step === STEPS.length - 1} onClick={() => move(step + 1)}
className="h-11 rounded-[10px] bg-primary px-5 text-sm font-medium text-primary-foreground hover:bg-[#2b2b2b] disabled:cursor-not-allowed disabled:opacity-45">Next</button>
</div>
</div>
);
}
See it in real apps
Still screenshots from the Inspireca Design library of the kinds of screen where this interaction is used. A screenshot cannot show the motion itself.