demo · v149
Multi-path sync
Without pathLength, synchronizing stroke-draw animations across multiple SVG paths requires measuring each path's pixel length with getTotalLength() and building custom stroke-dasharray values per path. With pathLength="100", every path uses the same normalised coordinate system — one CSS keyframe drives all of them in perfect sync.
Probing
CSS.supports('path-length', '100')…
In attribute mode every path below uses
pathLength="100" markup regardless of its actual pixel length. Switch to CSS property mode and the attributes are removed — a single .draw-path { path-length: 100 } rule does the normalisation instead. The CSS animation (stroke-dashoffset: 100 → 0) is identical for all. Hit Animate all and all six shapes draw together at exactly the same rate.
Normalise with:
Duration:
1.5s
Circle
px length: —
Star
px length: —
Wave
px length: —
Lightning
px length: —
Arrow
px length: —
Infinity
px length: —
| Shape | Actual pixel length | Normaliser in effect (observed) | stroke-dasharray / offset | getTotalLength() needed? |
|---|---|---|---|---|
| Measuring… | ||||
/* Without pathLength: you must measure each path in JS first */
const circle = document.querySelector('#circle');
const star = document.querySelector('#star');
const wave = document.querySelector('#wave');
circle.style.strokeDasharray = circle.getTotalLength(); // ~238px
circle.style.strokeDashoffset = circle.getTotalLength(); // ~238px
star.style.strokeDasharray = star.getTotalLength(); // ~347px
star.style.strokeDashoffset = star.getTotalLength(); // ~347px
// ... and so on for every shape. Different dasharray per shape
// means you can't use a single CSS keyframe for all.
/* Classic: pathLength="100" attribute on every element */
<circle pathLength="100" ...>
<path d="..." pathLength="100">
/* v149: the CSS path-length property — no per-element markup */
<circle class="draw-path" ...>
<path class="draw-path" d="...">
.draw-path {
path-length: 100; /* one rule normalises every path */
stroke-dasharray: 100; /* same for every shape */
stroke-dashoffset: 100; /* same for every shape */
animation: draw-on 1.5s ease forwards;
}
@keyframes draw-on {
to { stroke-dashoffset: 0; } /* one rule, all shapes */
}