Skip to content

Buttons with Loading State

Bootstrap 5 buttons that show a spinner, block repeat clicks while working and then display a success or error state, in solid, outline, pill and icon styles.

Also known as: button loading spinner, submit button loading state, async action button, button success error state

Bootstrap 5 Button Styles Responsive #button #loading #spinner #state

Buttons with Loading State live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A set of Bootstrap 5 buttons with a built-in loading state: on click they show a spinner and a "working" label, ignore further clicks and then switch to a success or error result before returning to normal. Use them for save, download, upgrade, delete and refresh actions that wait for a server.

How it works

The root is section.lbt-demo, a card with a .lbt-grid of .lbt-cell examples. Every button has the lbt-btn class and the same inner parts: a Bootstrap spinner (.lbt-btn__spinner, either spinner-border or spinner-grow), the normal icon .lbt-btn__icon, a result icon (.lbt-btn__done or .lbt-btn__fail) and the .lbt-btn__label text. CSS shows or hides these parts based on three state classes on the button: is-loading, is-success and is-error.

The script finds every .lbt-btn with a data-lbt-loading attribute and listens for click. It adds is-loading, sets aria-disabled and aria-busy, swaps the label to the data-lbt-loading text and writes it into the shared .lbt-status live region. After data-lbt-duration milliseconds the button gets is-success (green, check icon, data-lbt-success text) or, when data-lbt-result="error", is-error (dark red, warning icon, a short shake, data-lbt-error text). After RESET_AFTER milliseconds it returns to its original label. A busy flag blocks double submits for the whole cycle.

Two variants add extra feedback: .lbt-btn--progress fills the button from left to right with .lbt-btn__fill during the wait, and .lbt-btn--icon rotates its .lbt-btn__icon--spin arrow instead of showing a separate spinner. The last cell shows static markup for a loading button you can render from the server.

Customization

  • --lbt-ink and --lbt-ink-hover in .lbt-demo: recolor the solid, outline and icon buttons.
  • --lbt-grad-from and --lbt-grad-to in .lbt-demo: change the gradient of .lbt-btn--pill and the focus outline color.
  • --lbt-success, --lbt-danger and --lbt-danger-dark in .lbt-demo: change the result colors.
  • --lbt-radius in .lbt-demo: make the buttons square or rounder.
  • data-lbt-duration on any button: set the simulated wait; the progress fill uses the same value.
  • data-lbt-loading, data-lbt-success and data-lbt-error: change the texts shown and announced for each state.
  • RESET_AFTER in script.js: keep the result visible longer or shorter.
  • The window.setTimeout in the click handler: replace it with a fetch() and call finish(true) or finish(false).

Use cases

  • Admin panels: save and delete buttons show a spinner and block repeat clicks while the server responds
  • Download and export tools: a progress-fill button shows the wait, then confirms success or shows an error
  • SaaS upgrade flows: the pill upgrade button signals work in progress and returns to normal afterwards
  • Data dashboards: an icon refresh button spins its arrow while new data loads

Accessibility

Buttons keep keyboard focus while busy because they use aria-disabled instead of the disabled attribute, and aria-busy marks the work in progress. Each state change is announced through the visually hidden .lbt-status element with role="status". The icon-only button has an aria-label, and all icons and spinners are aria-hidden. Focus is shown with a thick outline. With prefers-reduced-motion: reduce the shake, fill and icon rotation are turned off and spinners slow down.

Usage notes

Requires Bootstrap 5 and Bootstrap Icons. Always guard against duplicate requests on the server as well.

Buttons with Loading State at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile
Category
Button Styles
License
Free for personal and commercial use

Questions about this template

Can I use the Buttons with Loading State code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Buttons with Loading State – free Bootstrap 5 button style template
Buttons with Loading State · free Bootstrap 5 button style template

More Button Styles

Gradient Buttons – free Pure CSS button style template

Gradient Buttons

Pure CSS gradient buttons with shifting colors on hover, a gradient outline, glow and shine effects, sizes and a disabled state.

3D Pushable Buttons – free Tailwind CSS button style template

3D Pushable Buttons

Tailwind CSS 3D buttons with a raised edge that lift on hover and press down on click, with sizes, icon buttons and toggles.

Animated Hover Buttons – free Pure CSS button style template

Animated Hover Buttons

Eight pure CSS hover buttons with fill, diagonal, sliding text, border drawing, arrow, underline and press effects that also run on focus.

Button Variants – free Tailwind CSS button style template

Button Variants

Tailwind CSS button set with primary, secondary, outline, ghost, danger and link variants, five sizes, icon buttons, loading and disabled states.