A song recording is finished sound that just plays back. Sheet music is only notes, and a musician has to play them every time. A GIF or a video is a recording: finished pixels that just play back. Lottie is sheet music: animation stored as JSON data (shapes, colours and every keyframe's value) that has to be played on every frame. The result is sharp at any size, but someone always has to do the work of playing it.
The data is exported from Adobe After Effects (a program for making animation) with the Bodymovin plugin (an add-on program). In the browser, a JavaScript player reads that data and redraws every frame into SVG (a picture written as tags) or into a canvas (an element you draw on with JavaScript). So the JSON file is the sheet music, and the player is the musician.
What's inside a Lottie file
This is Mrs. Sri's check-mark (a tick sign) as a Lottie, written by hand (1,634 bytes). The important parts:
{
"v": "5.12.2", "fr": 30, "ip": 0, "op": 60, "w": 48, "h": 48,
"layers": [
{ "ty": 4, "nm": "check", "shapes": [
{ "ty": "gr", "it": [
{ "ty": "sh", "ks": { "k": { "v": [[15, 24.5], [21.5, 31], [33, 18]] } } },
{ "ty": "st", "c": { "k": [0.290, 0.871, 0.502, 1] }, "w": { "k": 3 } }
] },
{ "ty": "tm", "e": { "a": 1, "k": [ { "t": 6, "s": [0] }, { "t": 15, "s": [100] } ] } }
] }
]
}
What the main keys mean:
| Key | Meaning |
|---|---|
v |
the version of Bodymovin that exported it |
fr |
frame rate: 30 frames per second |
ip, op |
first frame and end point: 0 to 60 |
w, h |
the size of its drawing area, 48 × 48 |
layers |
the animation's layers from After Effects; ty: 4 = a shape layer (a layer that holds shapes) |
sh, el |
shapes: a path (a line from point to point; v = its points) and an ellipse |
st |
stroke (the shape's line); its colour is RGBA from 0 to 1, so #4ade80 = [0.290, 0.871, 0.502, 1] |
tm |
trim path: what percentage of the line is drawn; e animates from 0 to 100 |
"a": 1, "k": [...] |
an animated value: a keyframe at frame t with value s |
The duration is (op - ip) / fr seconds: 60 / 30 = 2 seconds = 2,000 ms. Frames count from 0 and stop before op, so the last frame is 59, not 60. The progress (from 0 to 1) at frame 30 = 30 / 59 = 0.508, rounded to 0.51. In the exercise, the maths is the same.
The format has had an official specification (written rules) since 17 September 2024: Lottie 1.0 from the Lottie Animation Community, under the Linux Foundation. There is also dotLottie (.lottie), a ZIP file. It holds manifest.json (its list of contents), an a/ folder for the animations, and optionally i/ (images), t/ (themes) and s/ (state machines, rules for which animation plays when). It is usually smaller than the plain JSON.
Playing Lottie on the web
The classic player is Airbnb's lottie-web (MIT licence, version 5.13.0, last released 21 May 2025). The code below loads the check-mark's JSON shown above (checkJson) into the .check element, then controls it:
import lottie from 'lottie-web/build/player/lottie_svg';
const anim = lottie.loadAnimation({
container: document.querySelector('.check'), // the element the SVG is built in
renderer: 'svg', // 'svg' or 'canvas'
loop: false,
autoplay: false,
animationData: checkJson, // or path: '/animations/check.json'
});
anim.play(); // play
anim.pause(); // pause on the current frame
anim.stop(); // stop and go back to frame 0
anim.setSpeed(2); // twice as fast: 2 seconds become 1 second
anim.goToAndStop(30, true); // jump to frame 30 (true = a frame number, not milliseconds)
anim.playSegments([0, 15], true); // play only frames 0 to 15
setSpeed(2) then play() makes the animation twice as fast; it does not play it twice. anim.totalFrames holds 60, and the complete event tells you when it ends.
There is also a newer player, @lottiefiles/dotlottie-web (MIT, version 0.81.0). It draws into a <canvas> with a WebAssembly engine (a code format that runs fast in the browser). It reads both JSON and .lottie, and has DotLottieWorker, which draws in a Web Worker (a separate thread for JavaScript), off the main thread.
The cost: size and CPU
We measured the package size of each player, then played the same check-mark for 2 seconds in Chromium 147. gzip is how a server compresses a file before sending it:
| Downloaded (gzip) | JavaScript on the main thread, 2 seconds | Layout | |
|---|---|---|---|
| SVG + CSS | 312 bytes (515 bytes before gzip), no JavaScript | 0 ms | 0 |
lottie-web lottie_svg.min.js |
62 KB player (243 KB before gzip) + 1.6 KB JSON | 16.4 ms, 237 rAF calls; 43.1 ms with the CPU 4x slower | 60 |
| dotlottie-web | 33 KB JavaScript + 496 KB WebAssembly | 53.4 ms | none, canvas |
dotlottie-web DotLottieWorker |
the same | almost 0; 51.6 ms moved to the worker | none |
So for the check-mark in the "Booking sent" toast, the Lottie version downloads about 64 KB (the player alone is 62 KB), and the SVG + CSS version only 312 bytes. For a single icon, almost all the cost is the player. The full lottie.min.js build is bigger still: 306 KB, or 76 KB gzipped. By default, dotlottie-web also fetches its WebAssembly file from the jsDelivr CDN (a public server for library files).
Lottie is worth it for complex illustrations a designer made in After Effects, especially when they are used in many places and in Android and iOS apps too. For a check-mark, CSS is enough.
The same check-mark with SVG + CSS
This is the same check-mark, written directly as SVG with two paths: a ring and a tick.
<svg class="check" width="24" height="24" viewBox="0 0 48 48" aria-hidden="true">
<path pathLength="1" d="M24 4a20 20 0 1 1 0 40a20 20 0 1 1 0-40" /> <!-- ring -->
<path pathLength="1" d="M15 24.5l6.5 6.5L33 18" /> <!-- tick -->
</svg>
Then this CSS draws both lines a little at a time:
.check path {
fill: none; stroke: #4ade80; stroke-width: 3; stroke-linecap: round;
stroke-dasharray: 1; /* one dash as long as the path */
stroke-dashoffset: 1; /* shifted by the path's length: not visible yet */
animation: draw 300ms ease-out forwards;
}
.check path + path { animation-delay: 200ms; }
@keyframes draw { to { stroke-dashoffset: 0; } } /* shifted back to 0: drawn */
@media (prefers-reduced-motion: reduce) {
.check path { animation: none; stroke-dashoffset: 0; }
}
stroke-dasharraysets a dashed-line pattern: a piece of line, then a gap of the same length.stroke-dashoffsetshifts where that pattern starts.- The "draw-on" effect = a
stroke-dasharrayas long as the path, thenstroke-dashoffsetanimated from the path's length to 0. At the start you see the gap. At the end, the piece of line. pathLength="1"makes the path count as 1 long, so you don't have to measure it. Without it, measure withpath.getTotalLength()in JavaScript and use that number.stroke-dashoffsetis not a property that can animate on the compositor thread: the line is repainted every frame. With the main thread blocked for 500 ms, this CSS version stopped too (0 frames), just like lottie-web (1 frame). Cheap, but it still stops when the main thread is busy.
SVG also has its own built-in animation, SMIL (<animate>). In 2015 Chrome planned to remove it, but that plan was cancelled. SMIL runs in all three browser engines (Chromium, WebKit and Firefox).
Accessibility
- Decorative animation gets
aria-hidden="true". This attribute hides the icon from screen readers (programs that read pages aloud). The message is already in the toast's text withrole="status", which screen readers announce. An icon read out as well only adds noise. - "Reduce motion" = straight to the last frame. In CSS, use
animation: nonewith the end state. In lottie-web:if (reduce) anim.goToAndStop(anim.totalFrames - 1, true); else anim.play();. - Don't loop forever. A success icon plays once (
loop: false). Movement that starts by itself and lasts over 5 seconds needs a pause control (WCAG 2.2.2, from the web accessibility guidelines).
⚠️ Miscounted frames and an oversized player
- A 62 KB player for one icon. Measure first. A simple icon is lighter as SVG + CSS.
- Progress divided by
durationFrames. In the exercise,durationFramesis the number of frames. The last frame isdurationFrames - 1, so frame 30 of 60 = 30 / 59 = 0.51, not 0.5. - Frames held at
durationFrames. Frame 60 doesn't exist. Hold the frame (limit its value) between0at the bottom anddurationFrames - 1at the top. - Forgetting
aria-hiddenand "Reduce motion". Add both to every decorative animation.
TL;DR: Lottie is animation stored as JSON data, like sheet music, then redrawn every frame by a JavaScript player. The data is exported from After Effects (an animation program) with the Bodymovin plugin, and the Lottie 1.0 specification has existed since 17 September 2024. In the JSON, fr is frames per second and ip/op the first frame and end point. layers hold shapes (sh), strokes or lines (st) and trim paths (tm, the percentage of the line drawn). Duration = frames / fps × 1000 (60 / 30 = 2,000 ms). Frames count from 0, so the last frame = frame count - 1, and progress = frame / (frame count - 1): frame 30 = 0.51. dotLottie (.lottie) is a ZIP with manifest.json and an a/ folder. lottie-web 5.13.0 has loadAnimation, play, pause, stop, setSpeed(2) (twice as fast) and goToAndStop(30, true). The cost: the Lottie check-mark downloads about 64 KB gzipped (a 62 KB player) and runs 16.4 ms of JavaScript per 2 seconds on the main thread. The SVG + CSS version is only 312 bytes, with 0 ms of JavaScript. dotlottie-web draws into a canvas with WebAssembly and can move to a worker (a separate thread). The draw-on effect in CSS: stroke-dasharray (a dashed-line pattern) + stroke-dashoffset (a shift of that pattern) from the path's length to 0 (pathLength="1" makes the length 1). Decorative animation gets aria-hidden="true", and "Reduce motion" shows the last frame right away.
⚡ Sheet music, not a recording
Meaning: Lottie is animation stored as JSON data, like sheet music: it holds notes, not finished pixels like a GIF or video recording. The data is exported from Adobe After Effects (an animation program) with the Bodymovin plugin. In the browser, a JavaScript player reads that data and redraws every frame into SVG (a picture written as tags) or a canvas, like a musician playing from sheet music.
⚡ The last frame is 59
Guess first: a Lottie animation of 60 frames at 30 fps (frames per second). What is its progress (how far it has gone, from 0 to 1) at frame 30, 0.5?
0.51. Frames count from 0, so the last frame is 59, and 30 / 59 = 0.508.
Meaning: In Lottie JSON, fr is the frames per second, and ip and op are the first frame and end point. Its duration is (op - ip) / fr seconds: 60 / 30 = 2 seconds = 2,000 ms.
⚡ The price of a player
Meaning: The Lottie check-mark (a tick sign) downloads about 64 KB, and almost all of it is the player. The SVG + CSS version is only 312 bytes, with no JavaScript. Lottie is worth it for complex illustrations from a designer, not for one icon.
⚡ The draw-on effect in CSS
Write:
.check path {
fill: none; stroke: #4ade80; stroke-width: 3; stroke-linecap: round;
stroke-dasharray: 1; /* one dash as long as the path */
stroke-dashoffset: 1; /* shifted by the path's length: not visible yet */
animation: draw 300ms ease-out forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } } /* shifted back to 0: drawn */
Meaning: This code draws each path (line) of the .check icon a little at a time. pathLength="1" on the SVG makes the path count as 1 long, so you don't have to measure it. stroke-dasharray: 1 makes a dashed line whose one piece is as long as the path, and stroke-dashoffset shifts that pattern from 1 (not visible yet) to 0 (drawn). A decorative icon gets aria-hidden="true" (hidden from screen readers), and "Reduce motion" shows its end state right away.