Skip to Content
Zuri
Components

Spinner

An indeterminate loading indicator with an accessible label.

Live preview
Theme
Preview width
LoadingLoadingLoading balance

Use Spinner for a wait of unknown length, such as a payment being confirmed. If you know the progress, use Progress. For content-shaped loading, use Skeleton.

Installation

pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/spinner.json

Usage

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

<Spinner label="Confirming payment" />

It uses the current text colour, so it follows whatever it sits in, for example inside a button.

Props

Spinner extends native <span> props (except children) and spreads them onto the element, including ref (React 19).

Props
PropTypeDefaultDescription
size"sm" | "md" | "lg""md"16, 24 and 40 pixels.
labelstring"Loading"Announced to screen readers. Say what is loading.

Accessibility

  • It is a role="status" live region containing the label as visually hidden text, so it is announced politely when it appears.
  • The spinning graphic is hidden from screen readers.
  • Under prefers-reduced-motion it pulses (a fade) instead of rotating.

Tokens used

None of its own: it inherits currentColor.

Known limitations

  • A spinner on screen for less than a moment can flash; delay showing it if your waits are usually short.

Source

import { cva, type VariantProps } from "class-variance-authority";import type { ComponentProps } from "react";import { cn } from "@/lib/utils";const spinnerVariants = cva("inline-block", {  variants: { size: { sm: "size-4", md: "size-6", lg: "size-10" } },  defaultVariants: { size: "md" },});export interface SpinnerProps  extends Omit<ComponentProps<"span">, "children">,    VariantProps<typeof spinnerVariants> {  /** Announced to screen readers. Describe what is loading, e.g. "Loading balance". */  label?: string;}/** An indeterminate loading indicator. Under reduced motion it pulses instead of spinning. */export function Spinner({ className, size, label = "Loading", ...props }: SpinnerProps) {  return (    <span role="status" className={cn(spinnerVariants({ size }), className)} {...props}>      <svg        aria-hidden="true"        viewBox="0 0 24 24"        fill="none"        className="size-full animate-spin motion-reduce:animate-pulse"      >        <circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="3" opacity="0.25" />        <path          d="M21 12a9 9 0 0 0-9-9"          stroke="currentColor"          strokeWidth="3"          strokeLinecap="round"        />      </svg>      <span className="sr-only">{label}</span>    </span>  );}export { spinnerVariants };

On this page