webdevpuneet.com

Lottie Button Micro Loader — Free HTML CSS JS Snippet

Lottie Button Micro Loader · Buttons · Plain HTML, CSS & JS · Live preview

CategoryButtons

Copy & paste

Source Code

Requires
<div class="lbm-wrap">
  <button class="lbm-btn" id="lbmBtn" type="button">
    <span class="lbm-label" id="lbmLabel">Save changes</span>
    <span class="lbm-lottie" id="lbmLottie"></span>
  </button>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Loads the real lottie-web library from a CDN via cdnUrls
Inline animationData JSON object rendered at a small 22x22px size
Label and animation swap in place without changing button dimensions
Button disabled during the loading phase to prevent double-submits
Brief "Done" confirmation state before reverting to the original label
Lottie instance destroyed after use to avoid leaking animation players
Self-contained — no image or font assets required
Reusable pattern for any async button action

About this UI Snippet

Lottie Button Micro Loader — Inline Animated Loading State for Buttons

Screenshot of the Lottie Button Micro Loader snippet rendered live

This snippet replaces the usual CSS spinner inside a loading button with a real Lottie animation from the lottie-web library, rendered small enough to sit inline where the button's label normally lives.

Swapping label for animation

On click, the button's text label is hidden and a 22×22px container becomes visible, into which lottie.loadAnimation({ container, renderer: 'svg', loop: true, autoplay: true, animationData }) renders the looping animation using the same inline animation JSON object pattern as the other Lottie snippets in this library — no external .json file is fetched.

Timed completion

After roughly 1.5 seconds, a setTimeout callback destroys the Lottie instance, hides its container, and restores the label — first showing "Done" briefly, then reverting to the button's original text, giving the user clear confirmation the action completed before the button returns to its idle state.

Guarding against double-clicks

A busy flag combined with disabling the button during the loading phase prevents a second click from starting an overlapping animation instance while one is already running.

Step by step

How to Use

  1. 1
    Load the snippetClick "Lottie Button Micro Loader" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

💾
Form save and submit buttons
Show real loading feedback in place of the label, rendered as a small 22 by 22 pixel Lottie animation inside the button.
🔔
Async action buttons
Use for like, follow or subscribe buttons, with the button disabled during loading so a double click cannot submit twice.
💳
Checkout and payment buttons
Give users clear loading and Done states, with label and animation swapping in place without changing the button's dimensions.
🎓
Inline Lottie loader reference
Demonstrate loading the library from a CDN and playing inline animationData at a small size inside an existing control.

Got questions?

Frequently Asked Questions

No, this demo simulates the delay with setTimeout; replace the setTimeout body with your actual async request and trigger the completion state in its .then() or await continuation.

Calling destroy() releases the SVG DOM nodes and internal timers Lottie created, preventing memory and animation-frame leaks if the button is clicked many times.

Yes — increase the .lbm-lottie width and height in the CSS; the SVG renderer scales the same animationData cleanly to any size.

Design your website