How to Create a .lottie File

A task-focused guide to building a .lottie package from scratch using DotLottieBuilder.

How to Create a .lottie File

Use DotLottieBuilder whenever you're assembling a package from scratch rather than modifying one that already exists.

Assemble the content

const { DotLottieBuilder } = require("@lottiefiles/dotlottie-io");
const { readFileSync, writeFileSync } = require("node:fs");

const builder = new DotLottieBuilder();
builder.generator("my-tool v1.0");
builder.initialAnimation("intro");

builder.addAnimation("intro", readFileSync("intro.json"));
builder.addAnimation("hero", readFileSync("hero.json"));
builder.addTheme("dark", "Dark Theme", readFileSync("dark-theme.json"));
builder.addAudio("click.mp3", readFileSync("click.mp3"));

Build

const dl = builder.build();

console.log(dl.animationIds()); // ['intro', 'hero']
console.log(dl.audioFilenames()); // ['click.mp3']

build() validates the queued content and throws if anything is invalid — for example, an audio file that isn't .mp3.

Save the result

writeFileSync("output.lottie", dl.toBytes());

Adding more content after build()

build() returns a regular DotLottie instance, so you can keep adding to it with the same methods used during building:

dl.addImage("logo.png", readFileSync("logo.png"));
writeFileSync("output.lottie", dl.toBytes()); // re-serialize with the new image included

Producing an encrypted file directly

If the package should be distributed encrypted, pass a password to toBytes() instead of a separate step — see Password-Protecting Files.

Last updated: August 5, 2026 at 11:47 AMEdit this page