Lottie for Web

5.13.0 · active · verified Sun Apr 19

Lottie-web is a JavaScript library designed to render animations exported from Adobe After Effects as JSON files, leveraging the Bodymovin plugin. It enables designers to deliver complex, vector-based animations across web platforms without the need for manual re-coding by engineers, significantly streamlining the animation pipeline. The package, as of the provided context, is at version 5.13.0, which includes critical bug fixes and improvements, notably around Node.js compatibility for SSR. Lottie-web is actively maintained, with new features and bug fixes released periodically, though major versions with breaking changes (like the recent v6) are less frequent. Key differentiators include its tight integration with After Effects, robust performance across SVG and Canvas renderers, and a comprehensive API for controlling animation playback, speed, and segments. It is a core component of the broader Lottie ecosystem, alongside its counterparts for Android, iOS, and React Native, providing a unified animation solution.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `lottie-web`, initialize an animation using inline JSON data, and attach basic play/pause controls on mouse events.

import lottie from 'lottie-web';

const animationData = {
  v: '5.10.0',
  fr: 60,
  ip: 0,
  op: 180,
  w: 500,
  h: 500,
  nm: 'Simple Animation',
  ddd: 0,
  assets: [],
  layers: [
    {
      ddd: 0,
      ind: 1,
      ty: 4,
      nm: 'Square',
      sr: 1,
      ks: {
        o: { a: 0, k: 100, ix: 11 },
        r: { a: 0, k: 0, ix: 10 },
        p: { a: 1, k: [{t:0, s:[250,250,0]}, {t:90, s:[100,250,0]}, {t:180, s:[250,250,0]}], ix: 2},
        a: { a: 0, k: [25, 25, 0], ix: 1},
        s: { a: 0, k: [100, 100, 100], ix: 6}
      },
      ao: 0,
      shapes: [
        {
          ty: 'gr',
          it: [
            { ind: 0, ty: 'sh', ix: 1, ks: { a: 0, k: { i: [[-25,-25],[25,-25],[-25,25],[25,25]], o: [[25,-25],[-25,-25],[25,25],[-25,25]], v: [[-25,25],[25,25],[25,-25],[-25,-25]] }, ix: 2},
            { ind: 1, ty: 'fl', ix: 2, c: { a: 0, k: [0.7,0.2,0.1,1], ix: 3}, o: { a: 0, k: 100, ix: 4}},
            { ind: 2, ty: 'st', ix: 3, c: { a: 0, k: [0,0,0,1], ix: 5}, o: { a: 0, k: 100, ix: 6}, w: { a: 0, k: 2, ix: 7}, lc: 1, lj: 1, ml: 4}
          ],
          nm: 'Group 1', mn: 'ADBE Vector Group', hd: false
        }
      ],
      ip: 0, op: 180, st: 0, bm: 0
    }
  ],
  markers: []
};

function initLottieAnimation() {
  const container = document.getElementById('lottie-container');
  if (!container) {
    console.error('Lottie container not found!');
    return;
  }

  const anim = lottie.loadAnimation({
    container: container,
    renderer: 'svg', // Can be 'svg', 'canvas', or 'html'
    loop: true,
    autoplay: true,
    animationData: animationData // Or use 'path: "/path/to/animation.json"'
  });

  // Optional: Control animation playback
  container.addEventListener('mouseenter', () => anim.pause());
  container.addEventListener('mouseleave', () => anim.play());
}

document.addEventListener('DOMContentLoaded', initLottieAnimation);

// To make it runnable in a browser, you'd typically have this in an HTML file:
/*
<div id="lottie-container" style="width: 300px; height: 300px; background-color: #f0f0f0; border: 1px solid #ccc;"></div>
<script type="module" src="./main.js"></script>
*/

view raw JSON →