Button Loading and Success Animation
A pay button that shrinks into a spinner while work is in flight, then expands into a clear paid state.

A loading button is the control that has accepted a click and has not finished the job. The useful version does three things: it shows that the click landed, it refuses a second click, and it ends in a state you can name. “Pay $48” becomes a spinner, then “Paid”. The width animates from a full pill to a circle and back, which is the motion people mean by a morphing submit button.
The liquid button is the decorative hover. This one is the state machine. Use the liquid treatment on marketing. Use this treatment on the control that charges a card or saves a document.
The three states
Idle is a full-width black pill with the price. Loading adds is-loading, sets the width to the height so the pill becomes a circle, hides the label color, and draws a spinner on ::after. Success removes the spinner class, restores the width, and switches the background to green with the word Paid.
.pay {
width: 100%;
height: 52px;
border-radius: 999px;
background: #1c1917;
color: white;
transition: width .35s cubic-bezier(.2,.8,.2,1), background .3s ease;
}
.pay.is-loading {
width: 52px;
color: transparent;
margin-inline: auto;
}
.pay.is-loading::after {
content: "";
position: absolute;
inset: 14px;
border-radius: 50%;
border: 2px solid rgba(255,255,255,.35);
border-top-color: white;
animation: spin .7s linear infinite;
}
.pay.is-done { background: #166534; width: 100%; color: white; }
@keyframes spin { to { transform: rotate(1turn); } }
color: transparent hides the label without removing it from the button, so the accessible name can stay “Paying” while the spinner shows. Set that name in script when the class changes. A spinner with no text change leaves a screen reader on “Pay $48” during the request, which sounds like the click did not register.
The script
pay.addEventListener("click", () => {
if (pay.disabled) return;
pay.classList.add("is-loading");
pay.disabled = true;
pay.textContent = "Paying";
setTimeout(() => {
pay.classList.remove("is-loading");
pay.classList.add("is-done");
pay.textContent = "Paid";
}, 1100);
});
The timeout stands in for a request. In an application, move to is-done when the promise resolves, and to an error state when it rejects. An error state should restore the width, use a color that is not the success green, and put the label back to something you can click again, such as “Try again”. Leaving a spinner up after a failure is how people double-submit.
disabled blocks the second click. Also ignore clicks if the loading or done class is present, in case the button is not actually disabled because a form library re-enables it.
Success needs a word
A checkmark alone is ambiguous. “Paid” is the result. Green supports it. The word is what you would still understand in a screenshot with the color removed. The demo uses #166534 with white type, which clears contrast. A pale mint button with white type does not.
Reduced motion
Stop the spinner animation. The width change can stay short, or snap. The order of states still has to happen: label, wait, result. Reduced motion is not a reason to skip the result.
Questions about loading buttons
How do I animate a button into a loading spinner?
Transition the button’s width down to its height, hide the label color, and paint a spinning border on a pseudo-element. Disable the button for the duration of the request.
What should the button say when loading finishes?
The outcome, in words. “Paid”, “Saved”, “Sent”. Color and a check are support. The text is the state.
How do I stop a double submit?
Set disabled as soon as the first click is accepted, and ignore further clicks while the loading class is on. Re-enable only if you move to an error state that invites another try.