How it works
A loading button tells the user their click was received and the action is in progress. This preset shows the busy state: a 16px spinner placed before the label ("Saving" by default) inside a filled button. The spinner is a box with a 2px border in Text color at 25% opacity and a solid top border in Text color, turned by a spin keyframe. Because it uses the text color, it always contrasts with the button background.
The button gets aria-busy="true" and the spinner has aria-hidden, so screen readers hear the label and the busy state rather than an unnamed graphic. The layout is inline-flex with a 10px gap, so the spinner and text stay vertically centered at any font size.
Use it on form submits, "Pay" buttons and anything that triggers a network request. Parameters: Label, Button color, Text color, Corner radius, Duration and Easing. Change Label to the present participle of the action ("Saving", "Sending", "Paying") so the busy state describes itself. Keep Duration between 0.6 and 1s and Easing linear.
In real code, also set disabled or ignore repeat clicks while busy, and keep the button width stable between idle and busy states (a min-width works) so neighbouring elements do not shift. The spinner animates only transform, so it keeps turning while the main thread handles the request.
How do I switch between the normal and loading state?
Render the spinner element and aria-busy only while the request is pending. In React, keep an isPending boolean in state and conditionally render the spinner and the busy label. With plain HTML, toggle a class on the button that shows the spinner and changes the text. Re-enable the button and remove aria-busy when the request completes or fails.
Why does the spinner use the text color instead of the button color?
The spinner sits on top of the button background, so it needs to contrast with it, just like the label. Deriving both the track (25% opacity) and the arc from Text color guarantees that. If you change the button to a dark color with white text, the spinner turns white automatically.
Should the button be disabled while loading?
Usually yes, to prevent duplicate submissions. Be aware that a disabled button loses focus and some screen readers skip it. A common compromise is aria-disabled="true" plus ignoring clicks in your handler, which keeps focus on the button so the user hears when the label changes back.