# Spinner Overlay Button

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

- Category: [CSS Buttons](https://copy-css.com/category/buttons)
- Tags: loading, aria-busy, no layout shift, submit, state
- Live preview: https://copy-css.com/snippets/spinner-overlay-button
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<button class="btn-busy">Save changes</button>
<button class="btn-busy" aria-busy="true">Save changes</button>
```

## CSS

```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; }
}
```

## Notes

- 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.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
