Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Spinner for Radix UI

A loading spinner for React on Radix UI: a 16-pixel ring that turns in the color of nearby text, for busy buttons, syncing badges and form fields.

On this page9 sections

A spinner is a small ring that turns while something finishes: a button that's saving, a row that's syncing, a field being checked. It's Lucide's loader icon with Tailwind's animate-spin, 16 pixels by default and drawn in the color of the text around it, and it says nothing about how long the wait will be.

When you know the shape of what's loading, a Skeleton holds the layout in place. When the work has a number, a Progress bar shows how far it has gotten.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Spinner anatomy: item, spinner, title

Usage

import { Spinner } from "@/components/ui/spinner";
<Spinner aria-label="Loading orders" className="size-6 text-muted-foreground" />

Spinner takes the props of an svg. A size class replaces its 16 pixels, a text color tints it, and aria-label replaces the "Loading" a screen reader reads.

Accessibility

Spinner renders an svg with role="status" and an aria-label of "Loading", so a screen reader that reaches it reads "Loading". Pass your own aria-label to say what's loading, such as "Saving changes". The label also counts inside a parent: in a button that says "Please wait", a spinner beside the words makes the button read as "Loading Please wait". Set aria-hidden to true on a spinner whose message is already on screen, as Button's isLoading and the Button demo do.

When the system asks for reduced motion, the ring holds still, through the motion-reduce:animate-none class next to animate-spin. A still ring says less on its own, so keep a word beside it wherever the wait matters.

Demos

Custom

A spinner written in the demo itself, drawing LoaderIcon, Lucide's eight-spoke loader, with the same animate-spin, role="status" and "Loading" label as the shipped one. Use another glyph when the open ring clashes with the rest of your icons. Make the swap in components/ui/spinner rather than screen by screen, so every spinner changes together, Button's included.

Preview width

Size

Four spinners side by side at size-3, size-4, size-6 and size-8, which are 12, 16, 24 and 32 pixels. The second is the size it ships at, and with no size prop on Spinner, a class is how you change it. Pick the size from what sits beside it: 12 in a dense table cell, 16 next to body text, 24 or 32 alone in an empty panel.

Preview width

Button

Three small disabled buttons, Loading..., Please wait and Processing, each with a spinner before its label. data-icon="inline-start" marks it as the leading icon, which most styles answer by trimming the start padding, and aria-hidden keeps "Loading" out of the button's name. Pick this when the label should stay visible while the request runs, and isLoading on Button when a spinner centered over a hidden label will do.

Preview width

Badge

Three badges, Syncing, Updating and Processing, in the default, secondary and outline variants, each with a spinner before the word. The badge sizes any icon placed directly in it, 12 pixels in most styles, so the spinner matches the small text without a class. Use it for a status in a row or a table cell, where work runs on its own and there's nothing to press.

Preview width

Input group

A disabled message field with a spinner at its end, and a disabled textarea whose bottom bar reads Validating... with the send button pushed to the far side. Both spinners sit in an InputGroupAddon, where a field's icons go. Use it while a value is checked against the server and typing should wait, and move the spinner to the button when the wait belongs to sending.

Preview width

RTL

The payment row from the top of the page in Arabic, its amount in Arabic numerals, with dir set to rtl. The spinner now leads from the right edge and the amount sits at the left. The ring turns clockwise either way, since a spinner has no reading direction, so only the row around it needs to follow dir.

Preview width

FAQ

How do I show a loading Spinner inside a Button in React?

Set isLoading to true on Button. The button turns disabled and gets aria-busy, its label goes invisible while keeping its width and staying readable to screen readers, and a spinner sits centered on top. Set it back to false when the request settles.

To keep the label in view instead, put a Spinner before it with data-icon="inline-start" and aria-hidden set to true, and disable the button yourself with disabled, as the Button demo does. Without aria-hidden, the button is read as "Loading" followed by its label.

How do I change the size of a Spinner?

Give it a size class, as the Size demo does four times. It ships at size-4, which is 16 pixels, and a class you pass replaces that one: size-6 makes it 24 pixels and size-8 makes it 32. There's no size prop, and a width set as an attribute loses to the class.

Inside a Badge, the badge forces any icon placed directly in it to its own icon size, 12 pixels in most styles, with an important rule. A size class on the spinner does nothing there.

How do I change the Spinner color?

Set a text color. The ring strokes with currentColor, so it takes the color of the text it sits in: a button's foreground, a muted caption, a destructive alert.

Put a class such as text-primary or text-muted-foreground on the spinner to tint only the ring, or on its parent to tint the ring and the words beside it together. On a filled surface such as bg-primary, match the surface's foreground color, or the ring disappears into it.

Does the Spinner announce loading to screen readers?

It's labeled, not announced. The svg has role="status" and an aria-label of "Loading", so someone reading through the page hears "Loading" where it sits. A live region speaks when its content changes, though, and the spinner's never does, so don't rely on it to announce the wait as it starts.

For a spoken update, keep an element with role="status" on the page from the start and change its text: "Saving changes" when the work begins, "Saved" when it ends. Hide the spinner itself with aria-hidden set to true, so the two don't repeat each other.

Does the Spinner stop spinning when reduced motion is on?

It does. Spinner carries motion-reduce:animate-none next to Tailwind's animate-spin, so the ring makes one full turn a second until the system asks for reduced motion, and then holds still. Button's isLoading draws this same component, so its spinner stops too.

A still ring can look like a broken icon, so put a word next to it, "Saving" or "Loading orders", and let that carry the message for people who turn motion off. To keep it turning for them as well, remove that class from components/ui/spinner.

How do I change the Spinner icon?

Edit components/ui/spinner, which is your code once installed, and swap Loader2Icon, Lucide's open ring, for another icon. The Custom demo uses LoaderIcon, the eight-spoke loader. Keep animate-spin, role="status" and the default aria-label, so the new icon turns and is read the same way.

The change reaches every spinner in the app, including the one Button draws for isLoading. A custom SVG works as well, as long as it strokes or fills with currentColor, so text classes still tint it.

How do I stop a Spinner flashing on fast requests?

Wait a moment before showing it. Start a timer when the request begins, show the spinner only if the request is still running when the timer fires, a few hundred milliseconds in, and clear the timer when it settles. A request that answers inside that time never shows one.

Once the spinner is up, keep it for a short minimum, so a request that ends right after the delay doesn't make it blink. Button's isLoading shows its spinner the moment you set it, so put the delay in the state you pass to it.

When should I use a Spinner instead of a Skeleton or a progress bar?

Use a Spinner for a short wait whose length you don't know and whose result has no fixed shape: a form submitting, a row syncing, a field being validated. It takes 16 pixels and leaves the layout alone.

A Skeleton is the better fit when a whole region is loading and you know what it will look like, a feed or a table, because the page keeps its shape while it waits. When the work can report how far along it is, an upload or an import, a Progress bar says how much is left.

API Reference

Spinner

data-slot="spinner"

PropType
className?string

Merged with the part's classes.