v149 · CSS · SVG
path-length CSS property
Chrome 150 makes path-length a presentational CSS property for SVG paths. Previously, overriding the SVG pathLength attribute required touching the SVG markup. Setting path-length in CSS enables stylesheet-based control of stroke-dash animations, percentages in stroke-dasharray, and path-relative measurements.
concepts
-
Stroke Animation Demo
Animate SVG stroke-dashoffset to draw paths. With CSS
path-length, you set the normalized length (e.g. 100) in a stylesheet and compute dasharray offsets against that fixed unit — no measuring path lengths at runtime. -
Path Length Override
Compare a path with its native length vs an overridden
path-length. Shows how differentpath-lengthvalues scale the effective stroke-dasharray units, useful for creating repeating patterns at a consistent visual density. -
Signature Animator
Draw-on animation for four SVG path shapes — wave, loop, zigzag, heart — using
path-length: 100set in CSS (Chrome 150). The animation always runs stroke-dashoffset from 100 to 0, regardless of the path's actual geometric length. Adjust duration and stroke width live. -
Loading Spinner
Six spinner variants — from simple ring to multi-ring to CSS custom property parameterized — all using
path-length: 100so every@keyframesanimates between 100 and 0, regardless of the shape's actual circumference. No JavaScript measurement required. Feature-detected with graceful fallback. -
Scroll Progress
A sticky scroll-progress bar (linear) and a floating circle indicator both driven by a scroll listener that maps the scroll percentage directly to
stroke-dashoffset— possible only becausepath-length: 100normalizes both shapes to the same 0–100 unit space. Comparison of pre-150 vs post-149 code shown inline. -
Dash Pattern Normalizer
Six shapes — circle, star, zigzag, spiral, lines, heart — each with wildly different geometric lengths (28px to 400px). With
path-length: 100a singlestroke-dasharray: 8 4rule produces identical visual dash density across all of them. Toggle normalisation off to see each shape require a different dasharray value computed fromgetTotalLength().
why it shipped
SVG's pathLength attribute lets authors declare a virtual path length, making stroke-dasharray values relative to that unit instead of the true geometric length. The canonical draw-on-scroll and loader animations use this: set pathLength="1", then animate stroke-dashoffset from 1 to 0. Before Chrome 150, this required the pathLength attribute on each SVG element — the attribute couldn't be set in CSS. Chrome 150 makes path-length a presentation attribute accessible from CSS, enabling stylesheet-driven control with custom properties, @keyframes, and media queries.
the CSS property
/* SVG attribute (pre-Chrome 150) */
<path d="M10 80 Q95 10 180 80" pathLength="1" />
/* CSS property (Chrome 150+) */
path {
path-length: 1; /* set from CSS — no attribute needed */
stroke-dasharray: 1; /* full dash */
stroke-dashoffset: 1; /* start fully hidden */
animation: draw 2s forwards;
}
@keyframes draw {
to { stroke-dashoffset: 0; } /* reveal full path */
}
/* With custom properties — easy to parameterize */
.my-path {
--total: 100;
path-length: var(--total);
stroke-dasharray: var(--total);
}
references
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗