Lottie Button Micro Loader — Free HTML CSS JS Snippet

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

CategoryButtons

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.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Hand this snippet's HTML, CSS, and JavaScript to an AI coding assistant like Claude and ask it to adapt "Lottie Button Micro Loader" to your project — restyle it to match your design system, wire it up to real data instead of the static example, or port it to the framework you're building in.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a buttons component called "Lottie Button Micro Loader" using plain HTML, CSS, and vanilla JavaScript — no framework, no build step.

Requirements:
- Match the structure and behavior of the "Lottie Button Micro Loader" snippet from the UI Snippets Library.
- Keep the markup semantic and the styling self-contained (no external dependencies beyond what the original snippet uses).
- Keep the JavaScript vanilla, with no framework runtime required.
- Make it easy to restyle via CSS custom properties or class overrides so it can be dropped into a real project.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

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>

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 while a save request is in flight.
Async action buttons
Use for like, follow, or subscribe buttons that call an API on click.
Checkout and payment buttons
Give users clear loading and completion feedback during payment processing.
lottie-web integration example
Demonstrates loading and destroying a small inline Lottie instance in vanilla JS.

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.