Loading Button

Button locked in its loading state with an inline spinner and progress label.

Tailwind CSS
<button disabled class="inline-flex cursor-not-allowed items-center gap-2 rounded-xl bg-indigo-600 px-6 py-3 font-semibold text-white opacity-80">
  <svg class="h-5 w-5 animate-spin" viewBox="0 0 24 24" fill="none">
    <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
    <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"></path>
  </svg>
  Saving...
</button>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Success state

Swap to the success state after the action completes so users get clear confirmation.

Tailwind CSS

Dark

The dark version matches neutral interfaces where a colored button would clash.

Tailwind CSS

Outline

Use the outline loading button for secondary forms where the primary action is already solid.

Tailwind CSS

About this loading button

The loading button shows exactly what users should see while an action is in flight: the label swaps to a progress message and a spinner takes the place of the icon. The preview above shows the loading state itself, since that is the state developers usually struggle to design well.

It is built from an inline-flex button with a small SVG spinner using animate-spin. The disabled attribute plus cursor-not-allowed and reduced opacity signal that the button cannot be pressed again. The spinner is a circle track with a filled arc segment, which reads more crisply than a border-based spinner at small sizes.

Use this pattern on any action that hits the network: form submits, payments, file uploads, save buttons. Keeping the button the same width in both states avoids layout shift when the state flips.

The most expensive bug in web forms is the double submit: a user clicks Pay, the page hesitates, they click again, and two charges go through. It happens because a button that looks idle during a request invites another click. A loading button fixes this by changing state the moment the request starts, showing the spinner and refusing further presses until the work resolves.

The button is inline-flex with a small SVG spinner carrying animate-spin. The track is a full circle drawn at low opacity and the arc is a bright segment on top, which reads more crisply than a border spinner at small sizes. The disabled attribute does the real work of blocking clicks, while cursor-not-allowed and reduced opacity broadcast the locked state visually.

Requests that finish in under 300 milliseconds should skip the loading state entirely, or the button flickers and feels nervous. Add a short delay before swapping to the spinner, and a minimum display time of about half a second once it shows. For uploads or payments that run long, pair the button with a progress bar or percentage elsewhere on the page, since a lone spinner cannot say how much is left.

The half-measure version shows the spinner but forgets the disabled attribute, so the button looks busy yet still accepts clicks and the double submit happens anyway. The visual state and the functional lock must change together: disabled blocks the click, the spinner explains why. Test it by hammering the button during a slow request; if a second request fires, the pattern is decoration, not protection.

Where to use it

  • ✓ Form submit buttons that post data to an API
  • ✓ Pay and checkout buttons where double-clicks must be blocked
  • ✓ File upload triggers that wait on server processing
  • ✓ Save buttons in dashboards and settings pages

Customization tips

Swap the Saving... label for your own progress text like Uploading or Processing. Change h-5 w-5 on the SVG to resize the spinner, and restyle the disabled look with your own opacity or background shade. Pair it with your normal button markup and toggle between the two with component state.

Design notes

When to use

A loading button is the right pattern when a click starts an async action and you want to prevent double submits, like placing an order or saving a form. Locking the button in place with a spinner keeps the layout stable, unlike swapping in a separate loader that shifts content. The disabled state plus reduced opacity tells users the click registered and work is underway.

What to avoid

Do not leave a button in loading state with no timeout or error path, a spinner that never resolves is a dead end. Avoid changing the button width when the spinner appears, the layout jump feels glitchy. And do not use this for actions that take under half a second, the flicker of loading states is worse than a brief pause.

Accessibility

The disabled attribute is correct, but also announce the state change with aria-live so screen reader users know the action started. Do not rely on the spinner alone, since it is invisible to assistive tech.

Frequently asked questions

Should the button really be disabled while loading?

Yes. Disabling prevents double submissions, which is the most common bug this pattern exists to fix. The cursor-not-allowed style makes the locked state obvious.

How do I switch between the normal and loading state in React?

Keep an isLoading boolean in state. Render the spinner markup when it is true and your normal label and icon when it is false. Keep padding identical in both branches so the button does not change width.

Why use an SVG spinner instead of a border spinner?

The SVG version scales cleanly at any size and lets you style the track and arc separately with opacity utilities. Border spinners can look jagged at small sizes and are harder to color in two tones.

How do I stop the button from resizing when the spinner appears?

Give the button a fixed minimum width, or keep the label in the layout with visibility hidden instead of display none while loading. This element keeps its width stable by reserving the same space for the spinner row, so surrounding content never jumps when the state flips.

How does a loading button prevent double form submissions?

Set the disabled attribute as soon as the request starts, which blocks extra clicks and submits natively. Pair it with an internal flag in your submit handler as backup, in case the button gets re-enabled early. The cursor and dimmed style change is a visual cue, the disabled attribute is what actually stops the second request.

What should a screen reader announce while the button loads?

Put an aria-live polite region in or next to the button that reads Loading while the request runs, then updates to Done or the result. Keep the button label itself short and add aria-disabled true alongside the disabled attribute, so assistive tech reports the state change without you writing extra code.

Customize it with our tools