# Spinner

> Loading spinner for React and shadcn: a CSS arc that keeps turning while the main thread is busy and announces itself to screen readers.

A loading spinner that turns on the compositor, so it keeps spinning while the main thread is busy, and announces itself unless visible text already does. A quarter arc on a faint ring, the eased.dev status-badge mark; it pauses off-screen and freezes under reduced motion.

Also known as a loader.

- Tier: Free (MIT)
- Interaction: Loading
- Page: https://eased.dev/components/spinner
- Installs: motion
- Registry: https://eased.dev/r/spinner.json

## Install

```bash
npx shadcn add https://eased.dev/r/spinner.json
```

A quarter arc turning on a faint ring, the eased.dev status-badge mark, that announces itself to screen readers unless visible text already does.

## When to use

- A short wait with nothing to measure: saving, signing in, fetching search results.
- Inside a button or beside a label while an action runs.
- A small area that is refreshing, where a skeleton would be too much.

## When not to use

- A task with measurable progress, or one that takes more than a few seconds: use [Progress](/components/progress).
- Content loading into a known layout: use a [Skeleton](/components/skeleton).
- A pending button: [Button](/components/button) already renders this spinner while it is loading.

## Usage

```tsx saving.tsx
import { Spinner } from "@/components/eased/spinner/spinner";

export function Saving() {
  return (
    <p className="flex items-center gap-2 text-ui-sm text-text-muted">
      <Spinner size="sm" label={false} className="text-current" />
      Saving changes…
    </p>
  );
}
```

## Examples

### On its own

With no visible text, the default label is announced.

```tsx
<Spinner label="Loading messages" />
```

### Larger or custom sizes

`lg` sits beside 16px text; a number sets any diameter in px, and the ring's weight scales with it.

```tsx
<Spinner size="lg" />
<Spinner size={32} className="text-brand" />
```

## API reference

### Spinner

| Prop | Type | Default | Description |
|---|---|---|---|
| `size` | `"sm" \| "md" \| "lg" \| number` | `"md"` | `sm` 14px beside 12px text, `md` 16px beside 13–14px, `lg` 20px beside 16px, or any diameter in px. |
| `label` | `string \| false` | `"Loading"` | The announced name. `false` when visible text beside it already says what is happening. |
| `className` | `string` | `"text-text-muted"` | The colour comes from `currentColor`; set a text colour class here. |

## Accessibility

- With a label it is `role="status"` named by the label, e.g. "Loading" or "Saving".
- With `label={false}` it is hidden from assistive tech, so "Saving changes…" beside it is not read twice.
- The colour follows the text colour, so the arc keeps the contrast of the text it sits beside.

## Motion

One linear turn every 900ms, run by a CSS animation on the compositor, so it keeps spinning while the main thread is busy. It pauses while off-screen. Reduced motion: the arc freezes in place.

## Notes for AI

Use Spinner for short, unmeasured waits, `size="sm"` inside buttons and beside small text. Pass `label={false}` whenever visible text describes the wait, and a specific `label` ("Saving") otherwise.

Do not add a spinner to an Eased Button or Search Field yourself: they render this same spinner while loading. Do not set its size with width or height classes; use `size`, so the ring's weight scales too.

## Related

- [Progress](/components/progress): a bar for waits you can measure.
- [Skeleton](/components/skeleton): placeholders that hold the layout.
- [Button](/components/button): renders this spinner while loading.

## Example

`components/eased/spinner/spinner-demo.tsx`

```tsx
"use client";

import { AnimatePresence, motion, useInView } from "motion/react";
import { useEffect, useRef, useState } from "react";
import { Button } from "../button/button";
import { DemoFrame } from "../lib/demo-frame";
import { instant, reducedFade, snappy, useSafeReducedMotion } from "../lib/motion";
import { TextSwap } from "../text-swap/text-swap";
import { Spinner } from "./spinner";

const STEPS = [
  { name: "Install dependencies", ms: 1400 },
  { name: "Type-check", ms: 1100 },
  { name: "Build 214 pages", ms: 2200 },
  { name: "Upload to edge", ms: 1300 },
  { name: "Warm caches", ms: 900 },
];

export function SpinnerDemo() {
  const reduced = useSafeReducedMotion();
  const [current, setCurrent] = useState(0);
  const root = useRef<HTMLOListElement>(null);
  const inView = useInView(root);
  const finished = current >= STEPS.length;

  useEffect(() => {
    if (!inView || finished) return;
    const t = window.setTimeout(() => setCurrent((c) => c + 1), STEPS[current].ms);
    return () => window.clearTimeout(t);
  }, [current, finished, inView]);

  return (
    <DemoFrame
      title="Deploy"
      meta={finished ? "Ready" : "Building…"}
      actions={
        <Button size="sm" onClick={() => setCurrent(0)} disabled={!finished} swapKey={finished ? "idle" : "busy"}>
          {finished ? (
            "Redeploy"
          ) : (
            <>
              <Spinner size="sm" label={false} className="text-current" />
              Deploying…
            </>
          )}
        </Button>
      }
    >
      <ol ref={root} className="flex flex-col p-1.5" aria-label="Deploy steps">
        {STEPS.map((step, i) => {
          const state = i < current ? "done" : i === current ? "running" : "queued";
          return (
            <li
              key={step.name}
              aria-current={state === "running" ? "step" : undefined}
              className="flex h-10 items-center gap-3 rounded-control px-2.5 text-ui-sm"
            >
              <span className="relative grid size-4 shrink-0 place-items-center">
                <AnimatePresence initial={false} mode="popLayout">
                  <motion.span
                    key={state}
                    className="col-start-1 row-start-1 grid place-items-center"
                    initial={reduced ? { opacity: 0 } : { opacity: 0, scale: 0.6, filter: "blur(2px)" }}
                    animate={{ opacity: 1, scale: 1, filter: "blur(0px)" }}
                    exit={reduced ? { opacity: 0, transition: instant } : { opacity: 0, scale: 0.6, transition: { duration: 0.1 } }}
                    transition={reduced ? reducedFade : { ...snappy, opacity: { duration: 0.15 }, filter: { duration: 0.15 } }}
                  >
                    {state === "running" ? (
                      <Spinner label={false} className="text-text" />
                    ) : state === "done" ? (
                      <svg viewBox="0 0 16 16" aria-hidden className="size-4 text-success-text">
                        <circle cx="8" cy="8" r="7" className="fill-current opacity-15" />
                        <path d="M5 8.25 7 10.25 11 6" className="fill-none stroke-current" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" />
                      </svg>
                    ) : (
                      <span aria-hidden className="size-1.5 rounded-pill bg-text-disabled" />
                    )}
                  </motion.span>
                </AnimatePresence>
              </span>
              <span className={`min-w-0 flex-1 truncate ${state === "queued" ? "text-text-muted" : "text-text"}`}>{step.name}</span>
              <span className="text-ui-xs text-text-muted tabular-nums">
                <TextSwap swapKey={state}>
                  {state === "done" ? `${(step.ms / 1000).toFixed(1)}s` : state === "running" ? "Running" : "Queued"}
                </TextSwap>
              </span>
              <span className="sr-only">{state === "done" ? "Done" : state === "running" ? "In progress" : "Queued"}</span>
            </li>
          );
        })}
      </ol>

      <div className="mt-auto flex items-center gap-4 border-t border-line-subtle p-4 text-ui-xs text-text-muted">
        <span>Sizes</span>
        <Spinner size={12} label="Loading, 12px" />
        <Spinner size="sm" label="Loading, 14px" />
        <Spinner size="md" label="Loading, 16px" />
        <Spinner size="lg" label="Loading, 20px" />
        <Spinner size={22} label="Loading, 22px" className="text-text" />
      </div>
    </DemoFrame>
  );
}
```
