Lottie Animations
Add Lottie animations (.json and .lottie) to a design, and render them to MP4 or GIF in the browser, in Node.js or with the Cloud Render API
A lottie element plays a Lottie animation on the canvas. Its src is the URL or data URL of a .json Lottie or a .lottie file.
Add a Lottie element
In the editor: the Upload tab of the default Side Panel accepts Lottie files, next to images, video and audio. To store uploads on your own server, see setUploadFunc.
From code:
store.activePage.addElement({
type: 'lottie',
src: 'https://example.com/animation.lottie',
width: 300,
height: 300,
});In design JSON:
{
"id": "confetti",
"type": "lottie",
"src": "https://example.com/animation.json",
"x": 290,
"y": 290,
"width": 500,
"height": 500
}The element has the image element's properties, with keepRatio: true by default. See the Element API.
Playback
- The animation loops from the moment the element enters on the page timeline, as a video does.
- The element has no
duration. The page'sdurationsets how long it plays, 5000 ms by default. - The element takes
enter,exitandloopanimations like other elements. - Preview it in the editor with
store.play(), and stop withstore.stop().
Where it renders
| Renderer | Lottie |
|---|---|
Editor preview (store.play()) | Plays |
Browser GIF export (store.saveAsGIF()) | Plays |
Browser MP4 export (@polotno/video-export) | Plays |
polotno-node, GIF and MP4 | Plays |
Cloud Render API, gif and mp4 | Plays |
| Image export from the editor | With the playhead at the start, shows the last frame |
@polotno/image-export | Not drawn. The element is left out with an unsupported-element warning |
Lottie to MP4 in Node.js
polotno-node renders the design in headless Chromium and writes the MP4 file. It needs Node.js 22.17 or a later 22.x, or Node.js 24 or newer.
npm install polotno-nodeimport { createInstance } from 'polotno-node';
const json = {
width: 1080,
height: 1080,
pages: [
{
id: 'page-1',
background: '#0B2545',
duration: 3000, // video length in ms
children: [
{
id: 'lottie-1',
type: 'lottie',
src: 'https://example.com/animation.lottie',
x: 290,
y: 290,
width: 500,
height: 500,
},
],
},
],
};
const instance = await createInstance({ key: 'YOUR_API_KEY' });
await instance.jsonToVideoFile(json, 'out.mp4', { fps: 30, pixelRatio: 1 });
await instance.close();For a GIF, call instance.jsonToGIFBase64(json) and write the result to a file. The progress and stall options are on the Video Export page.
Lottie to MP4 with the Cloud Render API
Send the same JSON with format: 'mp4' (or 'gif'), then poll the job:
const req = await fetch('https://api.polotno.com/api/renders?KEY=YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ design: json, format: 'mp4' }),
});
const job = await req.json();
// later
const res = await fetch(`https://api.polotno.com/api/renders/${job.id}?KEY=YOUR_API_KEY`);
const { status, output } = await res.json();
if (status === 'done') {
console.log(output); // link to the MP4 file
}A src given as a URL must be reachable from the render servers. See Cloud Render API for webhooks and all options.
Related Pages
- Animations and Videos - Element animations, preview and export
- Video Export - MP4 export in the browser
- Server-side Rendering with Node.js -
polotno-nodesetup and options - Cloud Render API - Managed rendering