Spinner
Shows that something is loading when you cannot say how long it will take.
Installation
pnpm dlx shadcn@latest add @silkware/spinnerTo copy the component by hand, install its dependencies:
pnpm add cn lucide-reactThen copy the source into components/ui/spinner.tsx:
import { cn } from "cn"import { Loader2Icon } from "lucide-react"
function Spinner({ className, ...props }: React.ComponentProps<"svg">) { return ( <Loader2Icon data-slot="spinner" role="status" aria-label="Loading" className={cn("size-4 animate-spin", className)} {...props} /> )}
export { Spinner }Usage
import { Spinner } from "@/components/ui/spinner"<div className="flex items-center gap-3"> <Spinner /> Checking stock in Verona</div>A spinner is an icon with role="status" and the label "Loading". Put text next to it that says what is loading, and change the aria-label when the default is too vague.
Examples
Default
A spinner on its own, for a place where the text around it already names the wait. Give it an aria-label that says what is loading.
Size
The spinner is 16px (size-4) and takes its colour from the text around it. Change the size with a size-* class. Pick the size from the text it sits next to, not from the space available.
In a button
Use isPending on the button for an action that is running, and put a spinner at the start of the label. data-icon="inline-start" tightens the padding on that side. The button keeps its focus and ignores presses while it is pending. Change the label to say what is happening.
In a badge
A badge can show that a record is being worked on. Keep the label to one word.
In an input
Put the spinner in an InputGroupAddon at the end of a field while you check its value, for example against the ERP. Label the spinner with what is being checked.
Accessibility
A spinner is not interactive and does not take focus.
| Key | Action |
|---|---|
| Tab | Skips the spinner. It is not a control and is not in the tab order. |
The component provides:
role="status", which browsers expose as a polite live region, andaria-label="Loading". Assistive technology can announce it when it appears.- A decorative icon that inherits the text colour, so it works on every surface and in both themes.
- A rotation that stops when the person asks their system for reduced motion. The global reduced-motion rule leaves a still icon, so the label next to it matters more than the movement.
You provide:
- Visible text that says what is loading. The motion alone does not tell a sighted reader.
- An
aria-labelthat names the wait when "Loading" is not enough: "Checking the supplier code". - A message when the wait ends, in the content that replaces the spinner. Remove the spinner from the page when the work is done so it is not announced twice.
- Only one spinner for one wait. Several spinners announce several times.
Guidelines
When to use
- For a short wait whose length you do not know: opening an order, checking a code, saving a draft.
- Inside a button, a badge or an input, to show that the thing itself is working.
- Beside a line of text that explains a background task, such as "Syncing the Verona site".
When not to use
- For a task you can measure: an upload, an import, a sync of twelve sites. Use Progress.
- To hold the place of a table, a card or a page that is loading. Use Skeleton, which keeps the layout steady and shows what is coming.
- For a wait under a second. Show nothing: a spinner that flashes is more distracting than the wait.
- To report that something finished. Use a Toast or change the text.
Content
- Write the text next to it as a present-tense phrase with a verb: "Checking stock in Verona", "Sending order".
- Name the object. "Loading" says nothing the icon does not.
- Use sentence case and no ellipsis, full stop or exclamation mark; the motion already shows that it continues.
- Change the same label to the result when the work ends: "Order sent".
Where to put it
Place the spinner where the result will appear, or in the control that started the work. Do not centre one on a whole page unless the whole page is waiting.
Put text beside the spinner that says what is being loaded.
Don’t leave a large spinner on its own. The reader does not know what it waits for or how long to wait.
Use a spinner for a short wait you cannot measure.
Don’t use a spinner for work you can measure. Show the progress, so the reader can decide whether to wait.
API reference
Spinner
Renders the Lucide Loader2 icon as an <svg> with role="status", aria-label="Loading" and a spin animation. It accepts every prop of an svg; the role and label can be replaced.
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label? | string | "Loading" | The accessible name of the status. Say what is loading. |
role? | string | "status" | The ARIA role of the icon. |
className? | string | "size-4 animate-spin" | Classes merged after the defaults. Use a size-* class to change the size. |