Lottie in action — 6 ways to use Lottie, 31 more examples

Lottie is more than a file format: it is a way to put real motion into a page without video files. Below are six different effects, each playing live, with the code that drives it. Further down, a gallery of 31 more real animations — toggles, characters, weather, payments, and more — each playing live with its source and license. Every demo is a tiny vector animation — a few kilobytes — and each one links to the guide that explains the technique in depth. At the bottom, the real-world case shows what happens when a Lottie file is not vector at all.

1. Loading spinner — loop forever

The classic use case: an indeterminate loading indicator. A looping animation runs until the work finishes, then you remove it. Set loop: true and it plays indefinitely; call animation.destroy() when the load completes so it stops consuming CPU.

How to do it

import lottie from "lottie-web";

const animation = lottie.loadAnimation({
  container: document.getElementById("spinner"),
  renderer: "svg",
  loop: true,
  autoplay: true,
  animationData: spinnerJson,
});

// When the work finishes:
animation.destroy();

File: 1.3 KB — a pure vector animation, already tiny. Nothing to compress here; the compressor is for image-sequence files. How to embed Lottie in React · Best practices for shipping Lottie

2. Success checkmark — play once

A one-shot confirmation for a form submit, a payment, or an upload. Play it once with loop: false and listen for the complete event if you need to run code when it finishes — for example, to navigate to the next screen. Scroll down to it and it plays by itself; hit replay to see it again.

How to do it

const animation = lottie.loadAnimation({
  container: document.getElementById("check"),
  renderer: "svg",
  loop: false,
  autoplay: true,
  animationData: checkmarkJson,
});

animation.addEventListener("complete", () => {
  // e.g. navigate to the next screen
  showNextStep();
});

File: 1.8 KB — vector, already tiny. How to embed Lottie in React

3. Like button — play on click

Interactive animation: the motion is the feedback. The heart sits still until the user taps it, then plays its pop. Use goToAndPlay(0) to restart an animation from the first frame on every click — the standard pattern for like buttons, toggles, and favourite stars.

👆 Click the heart to play it

How to do it

const animation = lottie.loadAnimation({
  container: document.getElementById("like"),
  renderer: "svg",
  loop: false,
  autoplay: false,
  animationData: heartJson,
});

// Show the finished heart until the first click:
animation.goToAndStop(animation.totalFrames - 1, true);

document.getElementById("like").addEventListener("click", () => {
  animation.goToAndPlay(0);
});

File: 2.3 KB — vector, already tiny. How to embed Lottie in React

4. Hero animation — play when scrolled into view

A landing-page hero that starts when the visitor scrolls to it and pauses when it leaves the viewport, so it never burns CPU off-screen. An IntersectionObserver watches the container and calls play() / pause(). This is the right pattern for any ambient animation on a long page.

⏸ Paused (out of view)

How to do it

const animation = lottie.loadAnimation({
  container: document.getElementById("hero"),
  renderer: "svg",
  loop: true,
  autoplay: false,
  animationData: heroJson,
});

new IntersectionObserver((entries) => {
  if (entries[0].isIntersecting) animation.play();
  else animation.pause();
}).observe(document.getElementById("hero"));

File: 3.4 KB — vector, already tiny. Lottie vs GIF vs MP4 · Best practices for shipping Lottie

5. Playback control — speed, direction, seek, segments

lottie-web gives you full playback control: change the speed with setSpeed(), reverse with setDirection(-1), jump to any frame with goToAndStop(), and play just a slice with playSegments(). Try it below — the controls drive the same hero animation from demo 4.

How to do it

animation.setSpeed(2);        // 2x speed
animation.setDirection(-1);   // play backwards
animation.goToAndStop(45, true); // jump to frame 45

// Play only frames 0-30, then stop:
animation.playSegments([0, 30], true);

File: 3.4 KB (same hero animation as demo 4). How to embed Lottie in React

6. Morphing — scrub with scroll

A circle morphing into a square, driven by your scroll position. Instead of playing on a clock, the animation frame follows the page: goToAndStop(progress * totalFrames) on every scroll event. This is the technique behind scroll-linked storytelling — a diagram that builds itself as the reader scrolls, or a product that assembles step by step. Scroll through this section and watch the shape change.

↕ Scroll — frame 0 / 0

How to do it

// A morph is a shape path with the same number of
// points in every keyframe (circle -> square -> circle).
const animation = lottie.loadAnimation({
  container: document.getElementById("morph"),
  renderer: "svg",
  loop: false,
  autoplay: false,
  animationData: morphJson,
});

window.addEventListener("scroll", () => {
  const r = document.getElementById("morph").getBoundingClientRect();
  const progress = Math.min(1, Math.max(0,
    (window.innerHeight - r.top) / (window.innerHeight + r.height)));
  animation.goToAndStop(progress * (animation.totalFrames - 1), true);
});

File: 1.9 KB — vector, already tiny. How the lottie-mini compressor works

More examples — a growing gallery

31 more animations, all playing live, grouped by what they are for. Most are a few kilobytes of vector — already tiny, nothing to compress — which is exactly the point: Lottie covers everything from a 2 KB toggle to a full character scene. Animations come from useAnimations (MIT) and the LottieFiles community (Lottie Simple License); every card links to its source. New examples are added regularly — the gallery is a manifest, not a fixed list.

Vector animations this small do not need the compressor — the compressor is for image-sequence files (see the 70 MB case below). Want an animation of your own in this gallery? The sources above are free to use; the full list and the add-a-new-example steps are in docs/EXAMPLES.md in the repository.

The 70 MB case — when Lottie is not vector at all

Everything above is vector, so it is already tiny. But when a designer exports an After Effects composition with raster effects, Bodymovin falls back to embedding a PNG frame sequence — and the file explodes. This is the sample file from the lottie-mini repository: a 241-frame animation that shipped as a 70 MB JSON. The compressor re-encodes the frames to WebP, skips frames, and rewrites the timeline:

VersionSizeSmaller by
Original (PNG frames)70 MB—
Quality preset (all frames, WebP q75)2.1 MB33×
Balanced preset (half frames, WebP q75)1.1 MB64×
Smallest preset (half frames, 600px, q70)0.8 MB87×

The compressed file plays identically in every Lottie player. Press play to see the 1.1 MB balanced output running — it is the actual file the compressor produced from the 70 MB original.

Want to try it yourself? Load the bundled sample into the compressor — no file of your own needed.

Why your Lottie file is 70 MB →

Your turn

Have a Lottie file of your own? Drop it on the compressor — it runs 100% in your browser, nothing is uploaded.

Compress a file →Read the guides