FRENVersion française

Feedback

Spinner

Spinner

Demo

Loading demo…

A small spinning or pulsing animation that says "I'm working on it". It is used when you don't know how long the wait will last. It reassures people and keeps them from clicking twice.

Story

Did you know

The official technical name for the animated browser logo is "throbber". Netscape's showed shooting stars over an N, and Mosaic's a spinning globe.

Timeline

  1. 1993Mosaic animates its logo while pages load.
  2. 1990sNetscape and IE have their throbber in the top right corner.
  3. 2000sWith Ajax, animated spinner GIFs spread across the web.
  4. 2013+Skeletons replace spinners for content loading.

Vocabulary

Names

FR
Spinner, indicateur de chargement, loader, roue de chargement
EN
Spinner, throbber, activity indicator, loading spinner

Common uses

  • Button while submitting or exporting
  • Short wait of unknown length (API call)
  • Refreshing a list or a panel
  • Browser tab loading a page

Often paired with

The components it usually sits with, by page type, in reading order.

Code

<button id="export" type="button">
  <span class="spinner" aria-hidden="true" hidden></span>
  Export
</button>
<p id="status" role="status"></p>

<style>
  .spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
  .spinner[hidden] { display: none; }
  @keyframes spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
</style>

<script>
  const btn = document.querySelector('#export')
  const spinner = btn.querySelector('.spinner')
  const status = document.querySelector('#status')

  btn.addEventListener('click', async () => {
    if (btn.getAttribute('aria-disabled') === 'true') return
    btn.setAttribute('aria-disabled', 'true')
    spinner.hidden = false
    status.textContent = 'Exporting…'
    const res = await fetch('/api/export', { method: 'POST' }).catch(() => null)
    status.textContent = res?.ok ? 'Export ready' : 'Export failed'
    spinner.hidden = true
    btn.removeAttribute('aria-disabled')
  })
</script>

Good to know

  • A spinner is for short waits of unknown length. If you know the progress, or the wait goes past 10 s, switch to a progress bar: it has its own entry.
  • Avoid the flash: only show the spinner after 300 to 500 ms. Once it is visible, keep it up for a minimum time so it doesn't flicker.
  • In CSS, animate only transform: rotate(): the animation runs on the compositor, even while the main thread is busy.
  • Inside a button, keep the label and reserve room for the spinner (min-width or a grid) so the button doesn't resize. Watch out: display: inline-block overrides the hidden attribute.

Accessibility

Must have

  • A CSS spinner is invisible to screen readers. Set it to aria-hidden="true" and announce "Exporting…" then "Export ready" in a role="status" region that exists from page load.
  • Inside a button, don't replace the text with the spinner: the label stays the button's accessible name. A button that only contains an animated icon has no name left.

Often forgotten

  • disabled on the focused button throws that focus away. Prefer aria-disabled="true" and block double submits in code.
  • Under prefers-reduced-motion, slow the spin down or swap it for a static cue, without removing every sign of waiting: the text must be enough.
  • Announce failures too. A spinner that vanishes without a message suggests everything went fine.

Nice to have

  • aria-busy="true" on the area being updated, removed at the end.
  • If the wait drags on, update the message ("Still working…") to show nothing is stuck.

Who uses it