---
name: lottie
description: Renders After Effects animations as lightweight JSON on web and mobile using lottie-web. Use when adding vector animations, loading indicators, or complex motion graphics without video files.
---
# Lottie Web Animation
Render After Effects animations natively with lightweight JSON. Vector-based, scalable, and performant.
## Quick Start
```bash
npm install lottie-web
```
```javascript
import lottie from 'lottie-web';
const animation = lottie.loadAnimation({
container: document.getElementById('lottie-container'),
renderer: 'svg',
loop: true,
autoplay: true,
path: '/animations/loading.json' // or animationData: jsonObject
});
```
## loadAnimation Options
```javascript
const animation = lottie.loadAnimation({
// Required
container: document.getElementById('container'), // DOM element
// Animation source (use one)
path: '/animation.json', // URL to JSON file
animationData: importedJSON, // or imported JSON object
// Renderer
renderer: 'svg', // 'svg' | 'canvas' | 'html'
// Playback
loop: true, // boolean or number of loops
autoplay: true, // start immediately
name: 'myAnimation', // reference name
// Performance
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice',
progressiveLoad: true, // improve initial load
hideOnTransparent: true, // hide elements with 0 opacity
className: 'lottie-svg' // class for SVG element
}
});
```
## Animation Control Methods
```javascript
// Playback
animation.play();
animation.pause();
animation.stop(); // stop and go to first frame
// Speed & Direction
animation.setSpeed(2); // 2x speed
animation.setSpeed(0.5); // half speed
animation.setDirection(1); // forward
animation.setDirection(-1); // reverse
// Seek
animation.goToAndPlay(30, true); // frame 30, play
animation.goToAndStop(2, false); // 2 seconds, stop
// Second param: true = frames, false = seconds
// Segments
animation.playSegments([0, 30], true); // play frames 0-30
animation.playSegments([[0, 10], [20, 30]], false); // multiple segments
// Info
animation.getDuration(); // in seconds
animation.getDuration(true); // in frames
animation.totalFrames;
animation.currentFrame;
animation.isPaused;
// Cleanup
animation.destroy();
```
## Events
```javascript
// Event listener style
animation.addEventListener('complete', () => {
console.log('Animation completed');
});
animation.addEventListener('loopComplete', () => {
console.log('Loop finished');
});
animation.addEventListener('enterFrame', (e) => {
console.log('Current frame:', e.currentTime);
});
// All events
'complete' // non-looping animation finished
'loopComplete' // loop cycle finished
'enterFrame' // each frame (use sparingly)
'segmentStart' // segment started playing
'config_ready' // initial config loaded
'data_ready' // animation data loaded
'data_failed' // failed to load data
'DOMLoaded' // elements added to DOM
'destroy' // animation destroyed
```
## Global Lottie Methods
```javascript
import lottie from 'lottie-web';
// Control all animations
lottie.play(); // play all
lottie.play('myAnimation'); // play by name
lottie.stop();
lottie.pause();
// Settings
lottie.setSpeed(1.5); // all animations
lottie.setDirection(-1);
// State
lottie.freeze(); // suspend all animations
lottie.unfreeze(); // resume
// Responsive
lottie.resize(); // recalculate sizes
// Quality (canvas renderer)
lottie.setQuality('high'); // 'high' | 'medium' | 'low'
lottie.setQuality(2); // or number (1-10)
// Auto-discover
lottie.searchAnimations(); // find elements with class "lottie"
// Cleanup
lottie.destroy('myAnimation'); // by name
lottie.destroy(); // all
```
## React Integration
### Using lottie-react
```bash
npm install lottie-react
```
```jsx
import Lottie from 'lottie-react';
import animationData from './animation.json';
function MyAnimation() {
return (