Skip to content

From a comp to a file

Put an animation on a web page ​

You will export a comp and play it on a website, with the two players most sites use. About ten minutes; you need a text editor and a browser.

You needA comp that passes the audit for lottie-web (SVG) and dotLottie (ThorVG) (the default targets).
You getA .json or .lottie file and a few lines of HTML that play it.
TrialWorks for plain animations. The trial writes interactive comps as plain animations and does not optimize (what else).
Which player?dotLottie if the file is interactive or has themes, or you want the smaller file. lottie-web for a plain .json on a site that already uses it.

1. Check and fix the comp ​

Open the comp, Audit › Run Audit, fix what carries a tick, and look at the comp. What is left is listed with what to do by hand. Step by step: Audit and fix a comp.

2. Build the file ​

  1. In Build, switch on lottie (for dotLottie) or json (for lottie-web). Both is fine.
  2. Tick the comp and press Build selected.
  3. Go to Files, press the eye and compare the two players. If they agree, the web page will too.

Optional: Optimize the file in Files and Save the smaller copy (how).

3a. Play a .lottie with dotLottie ​

Put the file next to your page, then:

html
<canvas id="anim" style="width: 300px; height: 300px"></canvas>
<script type="module">
  import { DotLottie } from "https://cdn.jsdelivr.net/npm/@lottiefiles/dotlottie-web@0.83.2/+esm";
  new DotLottie({
    canvas: document.getElementById("anim"),
    src: "my-animation.lottie",
    autoplay: true,
    loop: true,
  });
</script>

An interactive file also takes stateMachineId: "machine_1" (the id the Studio shows); see the toggle tutorial.

3b. Play a .json with lottie-web ​

html
<div id="anim" style="width: 300px; height: 300px"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.13.0/lottie.min.js"></script>
<script>
  lottie.loadAnimation({
    container: document.getElementById("anim"),
    renderer: "svg",
    loop: true,
    autoplay: true,
    path: "my-animation.json",
  });
</script>

4. Open it ​

Open the page through a local web server, not by double-clicking the file: browsers refuse to load an animation file from a page opened straight from disk. Any server works, for example npx serve in the page's folder.

If it does not work ​

What you seeWhyFix
Nothing at all, and the browser console says the file was blockedThe page was opened from disk.Use a local server (step 4).
Text is missing or in the wrong fontThe player has no font for live text.Text as shapes (glyphs) in Export settings.
Something moves in After Effects but not on the pageAn expression; most players do not run them.Keep Bake expressions on.
Images are missing with a .json in folder modeThe images/ folder was not copied next to the file.Copy it, or use Embed in JSON (Images) or a .lottie.
It looks different from After EffectsThe player cannot draw something in the comp.Run the audit with your real targets; compare in Preview.

Want a quick file to send a client instead? Switch on Demo page in Build: one HTML file that plays the animation in any browser. All formats.

AXO for After Effects