Skip to content
All components
Primitives

Spinner

Show that work is in progress when its duration or completion cannot be measured.

An indeterminate loading indicator with a live region label.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add spinner

Then import it from @/components/ui/spinner. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Small

Place a small loading indicator beside compact content. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Spinner } from "@/components/ui/spinner"

export function SpinnerSmall() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <Spinner className="size-4" />
    </div>
  )
}

Large

Compare the larger loading indicator. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Spinner } from "@/components/ui/spinner"

export function SpinnerLarge() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <Spinner className="size-6 text-primary-base" />
    </div>
  )
}

Loading button

Compose loading feedback with a named button action. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"

export function SpinnerLoadingButton() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <Button disabled>
        <Spinner />
        Deploying
      </Button>
    </div>
  )
}

Button loading

Use the Button loading prop for an action in progress. The button keeps its width and focus, sets aria-busy and ignores repeated activation.

"use client"

import { Button } from "@/components/ui/button"

export function SpinnerButtonLoading() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <Button loading>Save changes</Button>
    </div>
  )
}

With text

Pair a decorative spinner with visible status text. The text is the status announcement; the spinner is hidden to avoid a duplicate.

"use client"

import { Spinner } from "@/components/ui/spinner"

export function SpinnerWithText() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <div className="flex items-center gap-2 text-paragraph-sm text-sub-600">
        <Spinner aria-hidden="true" role={undefined} aria-label={undefined} />
        <span role="status">Loading comments</span>
      </div>
    </div>
  )
}

Loading panel

Center a named spinner in a region that is loading. The region sets aria-busy and the spinner names what is loading.

"use client"

import { Spinner } from "@/components/ui/spinner"

export function SpinnerLoadingPanel() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <div
        aria-busy="true"
        className="flex h-32 w-full max-w-72 items-center justify-center rounded-12 border border-soft-200"
      >
        <Spinner className="size-6" aria-label="Loading activity" />
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Spinner

Indicate work in progress when completion cannot be quantified.

Spinner props
PropTypeDefaultDescription
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (14)
Spinner inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
maxstring | number | undefined—Maximum supported numeric value.
minstring | number | undefined—Minimum supported numeric value.
namestring | undefined—Name used by the control's form submission or primitive form integration.
typestring | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<SVGSVGElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<SVGSVGElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<SVGSVGElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<SVGSVGElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<SVGSVGElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<SVGSVGElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
refReact.Ref<SVGSVGElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/spinner.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Short indeterminate waits, from about one to ten seconds, such as fetching a panel or submitting a form.
  • Inside an action that is running, through Button's loading prop, which renders this spinner for you.
  • Next to visible status text such as 'Loading comments' in a region that is refreshing.

When not to use

  • Work with known progress, such as uploads or multi-step imports.
  • Initial page or list loads where the layout is known; a skeleton avoids layout shift.
  • Long-running jobs that continue in the background; show a status the user can leave and come back to.

Anatomy

Spinner
An SVG with role="status", aria-label="Loading" and a spin animation. Size and color come from className (default 16px in the secondary text color role).

Keyboard & interaction

  • Not focusable and not operable.
  • Its role and name are overridable: pass aria-label to say what is loading, or aria-hidden="true" with role and aria-label unset when visible text already announces the status.
  • The rotation stops under prefers-reduced-motion (motion-reduce:animate-none); the spinner stays visible as a static icon.
  • Mark the region that is updating with aria-busy="true" while the spinner shows, and remove it when content arrives.

Responsive behavior

  • Size the spinner relative to its context: 16px inline with text and in buttons, 24px or larger centered in a panel.
  • Center it in the area that is loading and keep that area's size reserved, so content does not jump when the spinner is replaced.
  • On small screens prefer a spinner in the affected region over a full-screen overlay that hides everything else.

Content guidelines

  • Name what is loading: aria-label 'Loading comments' rather than the generic 'Loading' when several regions can load.
  • Pair long waits with text that sets expectations, such as 'This can take up to a minute'.
  • When work fails, replace the spinner with a message that says what failed and how to retry.

Alternatives

  • Progress — Measurable completion with a value and maximum.
  • Skeleton — Loading content whose shape is known in advance.
  • Button — Its loading prop shows the spinner, keeps width and focus and blocks repeated activation.
  • Sonner — Background work whose result should be reported when it finishes.

Resources