Loader

A small busy indicator drawn in CSS: the button's spinner, three dots, three bars, a pulse, or a shape that turns from square to circle and back.

Loader

No script. Every variant is CSS animation behind motion-safe:.

Use it

<x-ds::loader />
<x-ds::loader variant="dots" size="sm" />
<x-ds::loader variant="bars" tone="accent" label="Uploading photos" />

Beside words, at the text's size:

<span class="inline-flex items-center gap-2">
    <x-ds::loader size="sm" /> Loading your reports
</span>

Props

PropTypeDefaultWhat it does
variantspinner dots bars pulse morphspinnerWhich drawing.
sizesm md lgmd16, 24 or 40px square.
toneneutral accent success warning dangerneutralIts colour; neutral is the muted text colour.
labelstringLoadingWhat is loading, read by a screen reader and never shown.

Which one

  • spinner is the one already in button's loading. Use it wherever a reader has seen the system's spinner before.
  • dots and bars are quieter, for a line of text or a chat reply.
  • pulse is for something live: a connection, a recording.
  • morph is decoration with a job: a long, single wait on an otherwise empty screen.

If you know how far along the work is, use progress instead: a bar that fills says more than any loader.

Motion

With reduced motion nothing moves, and none of them is a frame stopped halfway: the spinner becomes a dashed ring, the dots sit at three strengths, the bars at three heights, the pulse is a dot with a faint ring, and the morph shows the three shapes it would pass through in a row. Each still reads as busy. (The documentation image above is a frame of each animation, the morph at its square.)

Accessibility

  • It is role="status", with its label as text for screen readers only; the drawing is aria-hidden. A loader that appears after the page has loaded is announced by its words.
  • Name what is loading when there is more than one thing: "Loading comments" is useful, five "Loading"s are not.
  • Mark the region that is loading aria-busy="true" as well, and remove it when the content arrives. Skeleton swap does this for you.

Don't

  • Don't show one for under ~300ms. A flash of a spinner reads as a glitch; delay it.
  • Don't put one in a button. Use the button's loading, which also blocks a second press.
  • Don't use one for work with a known length. That is progress.
  • Don't stack variants for variety. One loader per screen, the same one every time.

More in specs/loader.md.


From the package repo: edit this page on GitHub.

Was this page helpful?