# Spinner: an accessible loading indicator in CSS

> iVOLT spinner: a compositor-only loading arc in the brand gradient, in three sizes, inside buttons and busy regions, with a calm reduced-motion fallback.

Source: https://ivolt.intervolutions.com/components/spinner · iVOLT 1.1.2 · English

An indeterminate busy indicator: something is happening and nobody knows for how long. The arc is a conic gradient in the brand colours, cut into a ring by a mask and turned with `rotate`, so the animation runs on the compositor and costs no layout or paint while it spins. Under reduced motion it stops turning and breathes instead.

**CSS:** `css/components/spinner.css` (in `ivolt.css`). **JS:** none. New in 1.1.

Couldn't load the demo. [Open alone](https://ivolt.intervolutions.com/stage/spinner/basic.html?id=fx-spinner-basic)

```html
<div class="iv-stack iv-u-gap-5">
  <div class="iv-cluster iv-u-items-center iv-u-gap-6">
    <span class="iv-spinner iv-spinner--sm" role="status"><span class="iv-u-sr-only">Loading (small)</span></span>
    <span class="iv-spinner" role="status"><span class="iv-u-sr-only">Loading</span></span>
    <span class="iv-spinner iv-spinner--lg" role="status"><span class="iv-u-sr-only">Loading (large)</span></span>
  </div>

  <div class="iv-cluster iv-u-items-center">
    <button class="iv-button iv-button--primary" type="button" disabled>
      <span class="iv-spinner iv-spinner--sm iv-spinner--current" aria-hidden="true"></span>
      Publishing…
    </button>
    <span class="iv-u-text-sm iv-u-text-muted">The button is disabled while it works; its text says what is happening.</span>
  </div>

  <section class="iv-card" aria-busy="true" aria-labelledby="spinner-card">
    <div class="iv-card__body iv-cluster iv-u-items-center iv-u-gap-3">
      <span class="iv-spinner" aria-hidden="true"></span>
      <div>
        <h3 class="iv-card__title iv-u-m-0" id="spinner-card">Building the preview</h3>
        <p class="iv-u-m-0 iv-u-text-sm iv-u-text-muted" role="status">Step 2 of 3: bundling the stylesheet.</p>
      </div>
    </div>
  </section>

  <p class="iv-u-m-0 iv-u-text-sm iv-u-text-muted">Demo: nothing is loading. Under reduced motion the arc stops turning and breathes instead.</p>
</div>
```

## When to use it

Use a spinner for short, unmeasured waits: a button that is saving, a panel that is fetching, a preview that is building. When you can say how far along a task is, use a [progress bar](https://ivolt.intervolutions.com/components/progress) instead — a number is always better than a turning shape. When the wait replaces content whose layout you know, a [skeleton](https://ivolt.intervolutions.com/components/skeleton) keeps the page from jumping when the content lands.

Show it only after a short delay (a few hundred milliseconds) for operations that are usually instant, so fast responses do not flash an indicator for one frame.

## Sizes and colour

`iv-spinner--sm` (0.875rem) fits inside a button or a table cell, the default (1.25rem) sits beside a line of text, and `iv-spinner--lg` (2.5rem) centres in an empty panel. `iv-spinner--current` drops the gradient and draws the arc in `currentColor`, which is what a spinner inside a filled primary button needs to stay visible.

## Accessibility

The ring itself says nothing. The words do, in one of two ways:

- **Alone** — give it `role="status"` and a visually hidden label: `<span class="iv-spinner" role="status"><span class="iv-u-sr-only">Loading</span></span>`. The status role is a polite live region, so the label is announced once.
- **In a region** — mark the region that is waiting with `aria-busy="true"`, make the spinner `aria-hidden="true"`, and put the visible explanation in a `role="status"` paragraph (“Step 2 of 3: bundling the stylesheet”). Remove `aria-busy` when the content is ready.

In a button, disable the button while it works and change its text (“Publishing…”): the label carries the state, the arc only decorates it. In forced colours the ring becomes a plain circle in the text colour with a gap, so it still reads as a spinner.

## Customising

```
.upload {
  --iv-spinner-size: 1.75rem;
  --iv-spinner-width: 3px;
  --iv-spinner-color: var(--iv-color-success);
}
```

Locals: `--iv-spinner-size`, `--iv-spinner-width` (the thickness of the ring) and `--iv-spinner-color` (the head of the arc; the primary by default, so a one-colour theme recolours it).

## Common mistakes

- A spinner with no text anywhere: a screen reader user hears nothing at all.
- A spinner for a task with a known size, such as an upload with a byte count.
- Several spinners on one screen for one operation. Show one, where the result will appear.
- Leaving a submit button enabled while it spins, which invites a second submission.

## Class index

Every class of the family. The full list per stylesheet lives in the [reference](https://ivolt.intervolutions.com/reference).

| Class | What it does |
| --- | --- |
| `iv-spinner` | A turning arc in the brand gradient. |
| `iv-spinner--sm` | Small, for buttons and cells. |
| `iv-spinner--lg` | Large, for empty panels. |
| `iv-spinner--current` | Arc in `currentColor`, for filled buttons. |
