Keyframery

Spinner

Spinners pop in where the work starts, then the ring turns at a steady pace while its arc stretches and shrinks, the one part allowed to keep moving.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/spinner

This adds components/keyframery/spinner.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

Usage

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

export default function Usage() {
  return <Spinner />
}

Examples

Sizes and drawings

size is sm, md or lg; variant="spokes" draws eight fading spokes instead of the stretching ring. It takes the text colour.

In a button

Put it in the button while the work runs. It pops in, and label tells screen readers what is happening.

Motion

MoveWhat you see
PopIt lands with a pop from 0.4 when it appears, usually in place of a label.
TurnThe ring turns at a steady pace while its arc stretches and shrinks; the spokes fade one after another around the dial.

Timing and springiness follow the motion style you set. To change how fast this spinner moves, pass speed:

<Spinner speed="fast">
  …
</Spinner>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--spinner-inkSpinner colourcurrentColor
--spinner-trackRing track colourcurrentColor
--spinner-ring-strokeRing thickness2.5
--spinner-spoke-strokeSpoke thickness2.25
--spinner-diameterCustom diameter14px / 16px / 24px by size
--spinner-opacitySpinner opacity1
--spinner-track-opacityTrack opacity0.16
--spinner-capStroke capsround

API reference

Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.

Spinner

Renders a <span>, and takes its props too.

Prop

Type

Accessibility

Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.

Built on UI SDK's core

UI SDK doesn't ship a spinner, so this one is defined with its core: one definePrimitive in components/keyframery/core/spinner-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/spinner.

Questions

How does the animated Spinner for UI SDK move?

Pop: It lands with a pop from 0.4 when it appears, usually in place of a label. Turn: The ring turns at a steady pace while its arc stretches and shrinks; the spokes fade one after another around the dial.

Do I need Motion or Framer Motion for the animated Spinner?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

UI SDK has no spinner. How is this one built on UI SDK?

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/spinner-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.

What happens to the Spinner when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page