CSS Spinner Overlay Button

A loading button that swaps its label for a centered spinner without changing width, driven by aria-busy.

  • loading
  • aria-busy
  • no layout shift
  • submit
  • state
HTML
<button class="btn-busy">Save changes</button>
<button class="btn-busy" aria-busy="true">Save changes</button>
CSS
.btn-busy {
  position: relative;
  padding: 14px 28px;
  border: 0;
  border-radius: 10px;
  background: #4f46e5;
  color: #fff;
  font: 600 16px/1 system-ui, sans-serif;
  cursor: pointer;
}

.btn-busy:hover {
  background: #4338ca;
}

/* The label keeps its space, so the button never changes size */
.btn-busy[aria-busy="true"] {
  color: transparent;
  pointer-events: none;
}

.btn-busy[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 18px;
  height: 18px;
  margin: auto;
  border: 2.5px solid #ffffff66;
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-busy-spin 0.7s linear infinite;
}

.btn-busy:focus-visible {
  outline: 3px solid #a5b4fc;
  outline-offset: 3px;
}

@keyframes btn-busy-spin {
  to { transform: rotate(1turn); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-busy[aria-busy="true"]::after { animation-duration: 2s; }
}

About this CSS Spinner Overlay Button

This CSS Spinner Overlay Button is 46 lines of pure CSS (0.9 KB) with no JavaScript and no dependencies. It uses keyframe animations, transforms, keyboard focus styles and reduced-motion support. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #4f46e5
  • #fff
  • #4338ca
  • #ffffff66
  • #a5b4fc

How to use this spinner overlay button

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .btn-busy class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback