DEV Community

Fazal Shah
Fazal Shah

Posted on

How to Add Lottie Animations to Your Website (Free JSON Files Included)

Lottie animations are small, crisp, and interactive. This guide covers finding free animations through production-ready implementation.

What Is Lottie?

Lottie is a JSON-based animation format from Airbnb. After Effects animations are exported via Bodymovin as small JSON files (10-100KB), rendered by a lightweight JS library.

Key advantages over GIF:

  • 10-50x smaller file size
  • Resolution independent vector quality on any screen
  • Interactive — play, pause, seek, speed control
  • Full alpha transparency — no halo effects

Step 1: Get Free Lottie JSON Files

IconKing Free Lottie Library — 500+ free animations: UI icons, loaders, flags, illustrations. No account needed.

Preview any file first: iconking.net/preview — drag and drop to instantly see how it plays.

Edit colors and speed: iconking.net/editor — swap colors, adjust timing, all in-browser.

Step 2: Install lottie-web

npm install lottie-web
Enter fullscreen mode Exit fullscreen mode

Or CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.12.2/lottie.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

Step 3: Basic Implementation

import lottie from 'lottie-web';

const animation = lottie.loadAnimation({
  container: document.getElementById('lottie-container'),
  renderer: 'svg',
  loop: true,
  autoplay: true,
  path: '/animations/my-animation.json'
});
Enter fullscreen mode Exit fullscreen mode

Step 4: React Component

import { useEffect, useRef } from 'react';
import lottie from 'lottie-web';

function LottieAnimation({ src, loop = true, size = 200 }) {
  const ref = useRef(null);
  useEffect(() => {
    const anim = lottie.loadAnimation({
      container: ref.current, renderer: 'svg', loop, autoplay: true, path: src
    });
    return () => anim.destroy();
  }, [src]);
  return <div ref={ref} style={{ width: size, height: size }} />;
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Playback Controls

animation.play();
animation.pause();
animation.setSpeed(1.5);
animation.goToAndStop(30, true);       // frame 30
animation.playSegments([0, 60], true); // frames 0-60 only
animation.addEventListener('complete', () => console.log('done'));
Enter fullscreen mode Exit fullscreen mode

Convert Lottie to Other Formats

All free, browser-based, no signup — iconking.net:

Performance Tips

Renderer: Use SVG for quality. Switch to canvas when rendering 5+ animations at once.

Lazy-load off-screen animations:

const observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      loadAnimation(entry.target);
      observer.unobserve(entry.target);
    }
  });
});
observer.observe(container);
Enter fullscreen mode Exit fullscreen mode

Always destroy on unmount to prevent memory leaks in SPAs.

Where to Get Free Lottie Animations


Building something with Lottie? Drop your project in the comments.

Top comments (0)