Animated Checkbox
A checkbox that draws itself — the standard micro-interaction for task lists and settings.
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.
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.
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
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.
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
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.
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
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.
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
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.
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
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.
// 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
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.
The switches, menus, and morphing controls every interface needs.
A checkbox that draws itself — the standard micro-interaction for task lists and settings.
A magnifier that morphs into a close button — the classic expandable-search toggle.
The hamburger that turns into an X — the most-used animated icon on the mobile web.
Play morphs into pause and back — the media-control toggle every player needs.
A switch that slides on and off — the canonical on/off control for settings.
A padlock that locks and unlocks — feedback for auth states and private content.
A house that draws itself — the home button and dashboard anchor, animated.
Errors, notifications, and live states — motion that tells the user something happened.
A cross that draws in to flag an error — pair it with a message, not on its own.
A bell that rings when something arrives — notification badges done in motion.
A heartbeat line that pulses — live data, health, and monitoring in one icon.
Save, rate, and like — the micro-interactions of feeds and reviews.
A bookmark that fills when saved — the save-for-later pattern in feeds and readers.
A star that pops when rated — the building block of 5-star ratings.
Volume, downloads, and scroll hints — controls that move.
A speaker that mutes and unmutes — the volume control for players and calls.
An arrow that drops into a tray — the download affordance, animated.
A chevron that nudges downward — the polite way to say there is more below.
Faces and creatures with personality — Lottie as character animation.
A cheeky face sticking its tongue out — playful reaction art for chats and stickers.
A winking face — the universal 'got it' reaction, in motion.
A little bird character bobbing along — character animation with real personality.
A dog, animated — proof that Lottie can carry a full character, not just icons.
A flock of birds in flight — looping ambient motion for headers and backgrounds.
Fog, storms, and wind — atmospheric motion for forecasts and moods.
Drifting fog — atmospheric weather motion for forecasts and moods.
A storm cloud with lightning — weather icons that actually feel like weather.
Wind blowing through — a weather state you can feel, not just read.
A rainbow that draws itself in an endless loop — ambient color for empty states and celebrations.
Cash and cards — the money moments in checkout and finance.
Cash, counted and stacked — the money moment in checkout and finance flows.
A credit card, presented with a flourish — the payment step, made tangible.
Gesture hints and pins — the first-run guidance every app needs.
A hand swiping right — the gesture hint every onboarding flow needs.
A map pin dropping in — location, arrival, and 'you are here' in one motion.
Celebrations, empty states, and loaders with a sense of play.
A red packet (红包) popping open — the celebration moment for Lunar New Year and rewards.
An empty box, gently animated — the friendly face of 'nothing here yet'.
A ball that bounces while you wait — a loader with physics, not just a spin.
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.
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:
| Version | Size | Smaller by |
|---|---|---|
| Original (PNG frames) | 70 MB | — |
| Quality preset (all frames, WebP q75) | 2.1 MB | 33× |
| Balanced preset (half frames, WebP q75) | 1.1 MB | 64× |
| Smallest preset (half frames, 600px, q70) | 0.8 MB | 87× |
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.
Have a Lottie file of your own? Drop it on the compressor — it runs 100% in your browser, nothing is uploaded.