Skip to content

Loading State Button

Button with integrated loading spinner and state management

Loading State Button

by FreeCsStyles Dev's

StatesFunctional
🌐🎨⚛️💚🅰️🔥☁️
#loading#spinner#async#form#submit#progress

Embed this component

Paste this snippet into any site — the design renders in a sandboxed iframe served from /embed/loading-button.

<iframe src="/embed/loading-button" sandbox="allow-scripts" loading="lazy" title="Loading State Button" style="border:0;width:100%;height:480px;overflow:hidden"></iframe>

Implementation code

Copy the HTML and CSS for Loading State Button, or grab a framework-specific implementation. The HTML and CSS variants are self-contained; framework variants assume that framework's project setup.

HTML
<button class="loading-button" disabled>
  <span class="spinner"></span>
  Loading...
</button>
CSS
.loading-button {
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  background: linear-gradient(to right, #3b82f6, #06b6d4);
  color: white;
  font-weight: 600;
  border: none;
  cursor: not-allowed;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0.8;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
LWC — HTML template
<template>
  <button class="loading-button" disabled={isLoading} onclick={handleClick}>
    <template if:true={isLoading}>
      <span class="spinner"></span>
      Loading...
    </template>
    <template if:false={isLoading}>
      <slot>Submit</slot>
    </template>
  </button>
</template>
LWC — JavaScript
import { LightningElement, api } from 'lwc';

export default class LoadingButton extends LightningElement {
  @api label = 'Submit';
  @api isLoading = false;
  
  handleClick() {
    this.dispatchEvent(new CustomEvent('buttonclick', {
      bubbles: true,
      composed: true
    }));
  }
}
LWC — CSS
.loading-button {
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  background: linear-gradient(to right, #3b82f6, #06b6d4);
  color: white;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: opacity 0.3s ease;
}

.loading-button[disabled] {
  cursor: not-allowed;
  opacity: 0.8;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
LWC — Configuration
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  <apiVersion>59.0</apiVersion>
  <isExposed>true</isExposed>
  <targets>
    <target>lightning__AppPage</target>
    <target>lightning__RecordPage</target>
    <target>lightning__HomePage</target>
  </targets>
</LightningComponentBundle>

Where Loading State Button fits

  • Form Submissions
  • API Calls
  • Async Actions
  • Data Processing

Interaction states & animations

  • Loading
  • Spinner

Topics

  • #loading
  • #spinner
  • #async
  • #form
  • #submit
  • #progress

Accessibility notes

Use aria-busy="true" when loading. Announce state changes to screen readers.

Browser support

  • All modern browsers