v149 · CSS · SVG
CSS path-length
The path-length CSS property maps to the SVG pathLength attribute, letting you control stroke-dash normalisation via the CSS cascade — enabling pure-CSS animated SVG paths with clean math.
concepts
-
Stroke Animator
Control
path-lengthinteractively and see how it rescalesstroke-dasharray/stroke-dashoffset— the normalised coordinate system makes percentage-based dash patterns trivial. -
Progress Rings
Pure-CSS circular progress indicators driven by CSS custom properties and
path-length: 100— no JavaScript dash arithmetic, juststroke-dashoffset: calc(100 - var(--pct)). -
Draw on Path
Pick a shape (heart, star, wave, zigzag, spiral) and drag a progress slider to draw its stroke using
stroke-dasharrayin normalised coordinates. Setpath-length: 100and percentages just work — nogetTotalLength()needed. -
Signature Draw
Cursive letter-by-letter stroke animation — each letter path uses
path-length: 100so the draw animation is a singlestroke-dashoffset: 100 → 0keyframe, identical for every letter regardless of its actual pixel length. No JS length measurement needed. -
Animated Chart
Bar and line chart where every SVG path uses
path-length: 100and animates fromstroke-dashoffset: 100to0— identical keyframes for every bar or line regardless of actual pixel length. Switch between bar and line mode; hit Animate to replay the draw-on reveal. -
Multi-path Sync
Six shapes with wildly different pixel path lengths — circle, star, wave, lightning bolt, arrow, infinity — all sharing a single CSS keyframe.
pathLength="100"normalises every shape sostroke-dashoffset: 100 → 0draws them in perfect sync. A reference table compares actual pixel lengths vs the uniform normalised length, and shows thatgetTotalLength()is never needed.
why it shipped
SVG's pathLength attribute has long enabled a handy trick: set pathLength="100" and your stroke-dasharray values become simple percentages rather than pixel lengths computed in JavaScript. The problem was that pathLength could only be set as a presentational attribute — not via CSS — so it was invisible to the cascade and couldn't participate in transitions or responsive overrides. The new path-length CSS property fixes this: it maps to the same underlying attribute, can be set in any stylesheet, inherits cascade rules, and is animatable with transition or @keyframes. Combined with CSS custom properties, it makes "draw on demand" SVG animations a one-liner.