Command Palette

Search for a command to run...

dotlottie-js

Discover dotlottie-js, a powerful JavaScript library for creating, reading, and manipulating .lottie files in browser and Node.js environments.

dotlottie-js: Programmatic dotLottie File Creation and Manipulation

Introduction

dotlottie-js is a comprehensive JavaScript library for programmatically creating, reading, manipulating, and exporting dotLottie (.lottie) files. Designed for both browser and Node.js environments, it provides developers with the tools to build sophisticated animation workflows, tooling, and content management systems that work with Lottie animations.

What is dotLottie?

Before understanding dotlottie-js, it's essential to understand the dotLottie (.lottie) format—an open-source, zipped archive format optimized for packaging Lottie animations. Think of it as a specialized ZIP container that bundles:

  • Multiple Lottie animations (JSON files)

  • Image assets (PNG, JPEG) used by animations

  • Audio assets for synchronized sound

  • Metadata (author, version, generator information)

  • Advanced V2 features like Theming and State Machines

Benefits include smaller file sizes through compression, simplified asset management, and enhanced capabilities beyond standard Lottie JSON files. Learn more at dotlottie.io.

Role in the Lottie Ecosystem

dotlottie-js occupies a specific position in the Lottie ecosystem:

┌─────────────────────────────────────────────────────────────┐
│                    Lottie Ecosystem                         │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  Creation/Design        Animation Tools                    │
│  └─ After Effects       (e.g., LottieFiles)                │
│                                                             │
│  ┌────────────────┐    ┌──────────────────┐               │
│  │  dotlottie-js  │───▶│  .lottie files   │               │
│  │  (Builder)     │    │  (Container)     │               │
│  └────────────────┘    └──────────────────┘               │
│         │                       │                          │
│         │                       ▼                          │
│  ┌────────────────┐    ┌──────────────────┐               │
│  │  relottie      │    │ dotLottie Players│               │
│  │  (Processor)   │    │  (Playback)      │               │
│  └────────────────┘    └──────────────────┘               │
│                                                             │
└─────────────────────────────────────────────────────────────┘
  • dotlottie-js: Creates and manipulates .lottie archives

  • Players: Render and play .lottie files (web, mobile, frameworks)

  • relottie: Processes and transforms Lottie JSON using AST-based plugins

Key Capabilities & Features

Core Operations

  • Create dotLottie Archives: Bundle multiple animations, images, and resources into a single .lottie file

  • Load and Parse Files: Read .lottie files from URLs, ArrayBuffers, or file systems

  • Manipulate Content: Add, remove, or modify animations, themes, and state machines

  • Manage Assets: Handle image and audio assets with automatic path resolution

  • Export Multiple Formats: Output as ArrayBuffer, Blob, Base64, or trigger browser downloads

  • Version Management: Work with and convert between V1 and V2 dotLottie structures

Advanced Features (V2)

  • Theming: Package multiple visual styles (color palettes, property overrides) in a single file

  • State Machines: Define interactive behaviors and animation control logic

  • Multi-Animation Support: Organize related animations with manifest-based selection

  • Metadata Management: Embed author, version, description, and custom metadata

Platform Support

EnvironmentSupportNotes
Browser✅ FullAll features including download() method
Node.js✅ FullUse toArrayBuffer() with fs module for file I/O
Edge Functions✅ PartialCheck runtime limitations for file I/O
Webpack/Vite✅ FullStandard module bundler support

Architecture & How It Works

Internal Structure

┌─────────────────────────────────────────────────────────┐
│              dotlottie-js Architecture                  │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  ┌──────────────┐                                      │
│  │  DotLottie   │  Main API Class                      │
│  │   Instance   │                                      │
│  └──────┬───────┘                                      │
│         │                                               │
│         ├─▶ Animation Manager   (add/remove/get)      │
│         ├─▶ Theme Manager        (V2 features)        │
│         ├─▶ State Machine Mgr    (V2 features)        │
│         ├─▶ Asset Manager        (images/audio)       │
│         ├─▶ Manifest Builder     (metadata)           │
│         └─▶ ZIP Archiver         (compression)        │
│                                                         │
│  Build Process:                                        │
│  1. Validate configuration                            │
│  2. Fetch remote resources (if URLs provided)         │
│  3. Process and embed assets                          │
│  4. Generate manifest.json                            │
│  5. Create ZIP archive structure                      │
│  6. Compress and output                               │
│                                                         │
└─────────────────────────────────────────────────────────┘

Build Workflow

  1. Instantiate: Create a DotLottie instance

  2. Configure: Add animations, themes, state machines, and assets

  3. Build: Call build() to fetch resources and compile the archive

  4. Export: Use download(), toArrayBuffer(), toBlob(), or toBase64()

Feature Matrix

Featuredotlottie-jsPlayersrelottie
Create .lottie files✅ Primary
Modify .lottie files✅ Primary⚠️ Indirect
Bundle animations
Manage assets
Add theming
Add state machines
Play animations✅ Primary
Transform JSON⚠️ Limited✅ Primary
AST processing✅ Primary
Optimize animations⚠️ Via assets
Browser runtime
Node.js runtime❌ Most

Quick Start

Installation

Install using your preferred package manager:

# npm
npm install @dotlottie/dotlottie-js

# pnpm
pnpm add @dotlottie/dotlottie-js

# yarn
yarn add @dotlottie/dotlottie-js

Basic Usage: Create and Download

import { DotLottie } from "@dotlottie/dotlottie-js";

async function createAnimation() {
  // 1. Create instance
  const dotlottie = new DotLottie();

  // 2. Add animation from URL
  dotlottie.addAnimation({
    id: "animation_1",
    url: "https://assets.lottiefiles.com/packages/lf20_jW54t3.json",
    name: "My Animation",
  });

  // 3. Build the archive
  await dotlottie.build();

  // 4. Download (browser) or export
  await dotlottie.download("my-animation.lottie");
}

Node.js: Export to File System

import { DotLottie } from "@dotlottie/dotlottie-js";
import { writeFile } from "fs/promises";

async function createAnimationNode() {
  const dotlottie = new DotLottie();

  // Add animation from local JSON object
  const animationData = {
    v: "5.9.6",
    fr: 60,
    ip: 0,
    op: 180,
    w: 512,
    h: 512,
    layers: [],
  };

  dotlottie.addAnimation({
    id: "animation_1",
    data: animationData,
  });

  await dotlottie.build();

  // Export as ArrayBuffer and save
  const arrayBuffer = await dotlottie.toArrayBuffer();
  await writeFile("output.lottie", Buffer.from(arrayBuffer));
}

Common Use Cases

1. Animation Authoring Tools

Build tools that allow designers to configure and export .lottie files:

const dotlottie = new DotLottie();

// Add multiple animations
dotlottie.addAnimation({
  id: "idle",
  data: idleAnimation,
});

dotlottie.addAnimation({
  id: "hover",
  data: hoverAnimation,
});

// Add theme for dark mode
dotlottie.addTheme({
  id: "dark",
  data: {
    colors: {
      primary: "#FFFFFF",
      accent: "#00AAFF",
    },
  },
});

await dotlottie.build();
await dotlottie.download("button-animation.lottie");

2. Server-Side Dynamic Generation

Generate customized animations on-demand:

import { DotLottie } from "@dotlottie/dotlottie-js";

async function generateUserAnimation(userId, brandColors) {
  const dotlottie = new DotLottie();

  // Fetch base animation
  dotlottie.addAnimation({
    id: "base",
    url: "https://cdn.example.com/base-animation.json",
  });

  // Add user-specific theme
  dotlottie.addTheme({
    id: "user_theme",
    data: {
      colors: brandColors,
    },
  });

  await dotlottie.build();
  return await dotlottie.toArrayBuffer();
}

3. Build Pipeline Automation

Automate animation bundling in CI/CD:

import { DotLottie } from "@dotlottie/dotlottie-js";
import { readFile, writeFile } from "fs/promises";
import { glob } from "glob";

async function bundleAnimations() {
  const dotlottie = new DotLottie();
  const animationFiles = await glob("src/animations/*.json");

  for (const file of animationFiles) {
    const data = JSON.parse(await readFile(file, "utf-8"));
    const id = file.match(/([^/]+)\.json$/)[1];

    dotlottie.addAnimation({
      id,
      data,
    });
  }

  await dotlottie.build();
  const buffer = await dotlottie.toArrayBuffer();
  await writeFile("dist/animations.lottie", Buffer.from(buffer));
}

4. Interactive Animation Builder

Create animations with state machine interactivity:

const dotlottie = new DotLottie();

dotlottie.addAnimation({
  id: "button_animation",
  data: buttonAnimationData,
});

// Add state machine for interaction
dotlottie.addStateMachine({
  id: "button_states",
  data: {
    descriptor: {
      id: "button_interaction",
      initial: "idle",
    },
    states: {
      idle: {
        animationId: "button_animation",
        segment: [0, 30],
        on: [{ event: "onMouseEnter", transitionTo: "hover" }],
      },
      hover: {
        animationId: "button_animation",
        segment: [30, 60],
        on: [
          { event: "onMouseLeave", transitionTo: "idle" },
          { event: "onClick", transitionTo: "clicked" },
        ],
      },
      clicked: {
        animationId: "button_animation",
        segment: [60, 90],
        on: [{ event: "onComplete", transitionTo: "idle" }],
      },
    },
  },
});

await dotlottie.build();

Tool Comparison

When to Use dotlottie-js

Use dotlottie-js when you need to:

  • Create .lottie files programmatically

  • Bundle multiple animations into a single file

  • Add themes or state machines to animations

  • Build animation authoring tools

  • Generate customized animations server-side

  • Automate animation packaging in build pipelines

  • Manage assets alongside animations

Don't use dotlottie-js when you:

  • Only need to play animations (use Players instead)

  • Need to transform/optimize Lottie JSON structure (use relottie)

  • Want to analyze animation features (use relottie)

dotlottie-js vs. Players

Aspectdotlottie-jsPlayers
PurposeCreate/manipulate archivesRender/play animations
Output.lottie filesVisual playback
RuntimeBuild-time or server-sideClient-side (browser/mobile)
Use caseTooling, automationEnd-user experience
Asset handlingBundle and manageLoad and render

Example workflow: Use dotlottie-js to create a .lottie file with themes, then use a Player to render it with runtime theme switching.

dotlottie-js vs. relottie

Aspectdotlottie-jsrelottie
Focus.lottie container formatLottie JSON transformation
ApproachFile packagingAST processing
StrengthMulti-animation bundlesDeep JSON manipulation
Plugin systemNoYes (unified.js)
Asset managementFull supportNot applicable
Use caseCreate archivesTransform animations

Example workflow: Use relottie to optimize/transform individual Lottie JSON files, then use dotlottie-js to bundle them with themes into a .lottie archive.

Combined Workflow

For enterprise applications, you might use all three:

// 1. Transform animations with relottie
import { relottie } from "@lottiefiles/relottie";
import relottieParse from "@lottiefiles/relottie-parse";
import relottieStringify from "@lottiefiles/relottie-stringify";
import optimizePlugin from "@lottiefiles/some-optimize-plugin";

const optimized = await relottie()
  .use(relottieParse)
  .use(optimizePlugin)
  .use(relottieStringify)
  .process(lottieJsonString);

// 2. Package with dotlottie-js
import { DotLottie } from "@dotlottie/dotlottie-js";

const dotlottie = new DotLottie();
dotlottie.addAnimation({
  id: "optimized",
  data: JSON.parse(optimized.value),
});

await dotlottie.build();
const dotlottieFile = await dotlottie.toArrayBuffer();

// 3. Play with a Player (in browser)
// <dotlottie-player src="path/to/file.lottie"></dotlottie-player>

Who Should Use dotlottie-js?

Primary Audiences

Developers building:

  • Animation authoring platforms (web apps, Figma plugins, desktop tools)

  • Content Management Systems (CMS) with animation support

  • Digital Asset Management (DAM) systems

  • Marketing automation platforms with dynamic content

  • Design systems with themeable animations

  • CI/CD pipelines with animation processing

Use case indicators:

  • Need to create .lottie files from code

  • Managing multiple animations as a package

  • Adding themes or interactivity to animations

  • Server-side animation generation

  • Automated animation workflows

  • Simple animation playback: Use dedicated Players instead

  • Runtime animation transformation: Use relottie for JSON manipulation

  • Design/creation: Use After Effects or design tools directly

API Overview

The library centers around the DotLottie class:

import { DotLottie } from "@dotlottie/dotlottie-js";

const dotlottie = new DotLottie({
  version: 2, // V1 or V2 format
  author: "Your Name",
  description: "Animation package",
});

Core Methods

MethodPurposeEnvironment
addAnimation(options)Add Lottie animationBoth
addTheme(options)Add visual theme (V2)Both
addStateMachine(options)Add interactivity (V2)Both
addImage(options)Add image assetBoth
build()Compile archiveBoth
download(filename)Trigger downloadBrowser only
toArrayBuffer()Get raw binaryBoth
toBlob()Get BlobBrowser only
toBase64()Get Base64 stringBoth
fromArrayBuffer(buffer)Load existing fileBoth

Code Example: Complete Workflow

import { DotLottie } from "@dotlottie/dotlottie-js";

async function completeExample() {
  // Create with metadata
  const dotlottie = new DotLottie({
    version: 2,
    author: "Design Team",
    description: "Product animations with dark mode",
  });

  // Add animations
  dotlottie.addAnimation({
    id: "loading",
    url: "https://example.com/loading.json",
    name: "Loading Spinner",
  });

  dotlottie.addAnimation({
    id: "success",
    data: successAnimationData,
    name: "Success Checkmark",
  });

  // Add light and dark themes
  dotlottie.addTheme({
    id: "light",
    data: { colors: { primary: "#000000" } },
  });

  dotlottie.addTheme({
    id: "dark",
    data: { colors: { primary: "#FFFFFF" } },
  });

  // Add image asset
  dotlottie.addImage({
    id: "logo",
    url: "https://example.com/logo.png",
  });

  // Build and export
  await dotlottie.build();

  // Choose export method based on environment
  if (typeof window !== "undefined") {
    // Browser: download
    await dotlottie.download("animations.lottie");
  } else {
    // Node.js: save to file
    const buffer = await dotlottie.toArrayBuffer();
    await writeFile("animations.lottie", Buffer.from(buffer));
  }
}

Performance Considerations

Best Practices

  1. Reuse instances: Create one DotLottie instance per archive

  2. Build once: Call build() only after all content is added

  3. Optimize animations: Use relottie to optimize JSON before bundling

  4. Lazy load: For large archives, load animations on-demand from URLs

  5. Compression: The format automatically compresses; no additional steps needed

Memory Management

  • Large files: Use streams when available (Node.js)

  • Multiple archives: Clear references after export

  • Asset handling: Images are automatically embedded and compressed

Next Steps

Getting Started

Core Concepts

Advanced Topics

Reference

Ecosystem

Last updated: April 10, 2026 at 9:12 AMEdit this page