Interactive Example · Buttons
Button press, loading and success feedback
A button that dips when pressed, shows a spinner while it works and confirms when it is done, with words that carry the meaning at every step.
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.
How it works
A press should be answered at once. This button gives three answers in a row: a small dip while it is held, a spinner while the work runs, and a tick with the word "Saved" when it finishes.
What moves
- Press: the button scales to 97% for 100 milliseconds. It is short enough to feel like a physical response rather than an animation.
- Loading: a spinner appears in front of the label, and the label changes to "Saving…". The button keeps its width, so nothing beside it shifts.
- Success: the spinner is replaced by a tick and the label reads "Saved" for a moment before returning.
Timing
Response-time research summarised by the Nielsen Norman Group gives about a tenth of a second as the limit for something to feel instant, and about one second before people notice they are waiting. So acknowledge the press within 100 ms, and show the loading state for anything that may take longer than that.
When to use it, and when not
Use it for an action that takes a noticeable time and that the person would otherwise press twice: save, send, pay. Do not add a success state to actions that visibly do something already, such as opening a page.
Accessibility notes
- The words do the work. "Saving…" and "Saved" are in the label, so the state is clear without seeing the spinner or the tick.
- Announced, not just shown. A hidden status line with
role="status"repeats the result for screen readers (WCAG 2.2, 4.1.3 Status Messages). - Focus stays put. While saving, the button is marked
aria-disabledrather than disabled, so keyboard focus is not thrown elsewhere; presses are ignored until it finishes. - Reduced motion: the dip and the spinner's rotation are switched off; the label still changes.
- Size: 48 px tall, above the 44 to 48 guidance explained in contrast and touch targets.
The code
This is the source of the preview above: React with Tailwind CSS classes (press-feedback-button.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 { useEffect, useState } from "react";
import { Check, Loader2 } from "lucide-react";
import type { DemoProps } from "@/lib/examples/keys";
type Phase = "idle" | "loading" | "success";
/**
* A button that answers every press: it dips slightly while held, shows a spinner while the
* work runs, then confirms. The label always says what is happening, so the meaning never
* depends on the animation.
*/
export default function PressFeedbackButton({ values }: DemoProps) {
const forced = String(values.state);
const [phase, setPhase] = useState<Phase>("idle");
// Pretend to save: 1.4 s of work, then show "Saved" for 1.6 s.
useEffect(() => {
if (phase === "idle") return;
const timer = window.setTimeout(() => setPhase(phase === "loading" ? "success" : "idle"), phase === "loading" ? 1400 : 1600);
return () => window.clearTimeout(timer);
}, [phase]);
const shown: Phase = forced === "interactive" ? phase : forced === "loading" || forced === "success" ? forced : "idle";
const busy = shown === "loading";
return (
<div className="flex flex-col items-center gap-3">
<button
type="button"
disabled={forced === "disabled"}
// While busy the button stays focusable (so focus is not lost) but ignores presses.
aria-disabled={busy || undefined}
onClick={() => { if (!busy && forced === "interactive") setPhase("loading"); }}
className="inline-flex h-12 min-w-44 items-center justify-center gap-2 rounded-[10px] bg-primary px-6 text-[15px] font-medium text-primary-foreground transition-transform duration-100 ease-out hover:bg-[#2b2b2b] active:scale-[0.97] disabled:cursor-not-allowed disabled:bg-surface-strong disabled:text-muted-foreground disabled:active:scale-100 motion-reduce:transition-none motion-reduce:active:scale-100"
>
{busy && <Loader2 aria-hidden className="size-4 animate-spin motion-reduce:animate-none" />}
{shown === "success" && <Check aria-hidden className="size-4" />}
<span>{busy ? "Saving…" : shown === "success" ? "Saved" : "Save changes"}</span>
</button>
{/* Announces the result to screen readers without moving focus. */}
<p role="status" className="sr-only">{busy ? "Saving" : shown === "success" ? "Saved" : ""}</p>
</div>
);
}
Prompt to recreate it
Replace everything in [SQUARE BRACKETS]. Treat the result as a first draft and test it with a keyboard.
Build a [FRAMEWORK, e.g. React] button component for the action "[ACTION, e.g. Save changes]" with four states: idle, loading, success and disabled. Behaviour: - On press, scale to 0.97 for 100 ms. - While the action runs, show a spinner before the label and change the label to "[LOADING LABEL]". Keep the button the same width. Ignore further presses but keep the button focusable (aria-disabled, not disabled). - On success, show a tick and "[SUCCESS LABEL]" for about 1.5 s, then return to idle. On failure, return to idle and show an error message next to the button. - Announce loading and success through a role="status" element. - With prefers-reduced-motion, remove the scale and the spinner rotation but keep the label changes. Use my design tokens: [COLOURS, RADIUS, HEIGHT]. Minimum height 44 px. Show me the component and one example of using it with an async function.
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.