-
Notifications
You must be signed in to change notification settings - Fork 23.2k
Editorial review: Document the path-length CSS property #44563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hamishwillee
merged 6 commits into
mdn:main
from
chrisdavidmills:svg-path-length-property
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e43cf53
Document the path-length CSS property
chrisdavidmills 34cce86
Claude fixes
hamishwillee 8dab85d
Update files/en-us/web/css/reference/properties/path-length/index.md
chrisdavidmills e27ffce
A few review fix updates
chrisdavidmills 9cae5f4
A few more fixes
chrisdavidmills ec3ad7b
Remove incorrect/confusing bits
chrisdavidmills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
files/en-us/web/css/reference/properties/path-length/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| --- | ||
| title: "`path-length` CSS property" | ||
| short-title: path-length | ||
| slug: Web/CSS/Reference/Properties/path-length | ||
| page-type: css-property | ||
| browser-compat: css.properties.path-length | ||
| sidebar: cssref | ||
| --- | ||
|
|
||
| The **`path-length`** [CSS](/en-US/docs/Web/CSS) property specifies a total path length, in user units. All path computations are then scaled using the ratio `path-length` / _(computed value of path length)_ — this includes text paths, animation paths, and various stroke operations. | ||
|
|
||
| The `path-length` property only applies to {{SVGElement("circle")}}, {{SVGElement("ellipse")}}, {{SVGElement("line")}}, {{SVGElement("path")}}, {{SVGElement("polygon")}}, {{SVGElement("polyline")}}, and {{SVGElement("rect")}} elements nested in an {{SVGElement("svg")}}. | ||
|
|
||
| > [!NOTE] | ||
| > If present, the `path-length` CSS property overrides an SVG element's {{SVGAttr("pathLength")}} attribute. | ||
| > This property doesn't apply to SVG, HTML, or pseudo-elements other than those listed above. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```css | ||
| /* Keywords */ | ||
| path-length: none; | ||
|
|
||
| /* <length> values */ | ||
| path-length: 0; | ||
| path-length: 70; | ||
| path-length: 500; | ||
|
|
||
| /* Global values */ | ||
| path-length: inherit; | ||
| path-length: initial; | ||
| path-length: revert; | ||
| path-length: revert-layer; | ||
| path-length: unset; | ||
| ``` | ||
|
|
||
| ### Values | ||
|
|
||
| - `none` | ||
| - : No author path length is specified and the user agent's own computed path length is used for all path-related calculations. | ||
|
|
||
| - `<length>` | ||
| - : A non-negative unitless value representing an author-defined total path length, in user units. | ||
|
|
||
| ## Formal definition | ||
|
|
||
| {{CSSInfo}} | ||
|
|
||
| ## Formal syntax | ||
|
|
||
| {{csssyntax}} | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic usage | ||
|
|
||
| This example defines a path and shows how to apply a path length to it using the `path-length` CSS property. | ||
|
|
||
| #### SVG | ||
|
|
||
| Our SVG defines a single curved {{SVGElement("path")}} element with a colored {{SVGAttr("stroke")}}. It includes a {{SVGAttr("stroke-dasharray")}} attribute that defines a regular dashed pattern for the stroke. | ||
|
|
||
| ```html live-sample___basic-path-length live-sample___path-length-animation | ||
| <svg viewBox="0 0 600 200"> | ||
| <path | ||
| d="M 30 100 C 150 20, 250 180, 380 100 S 520 20, 570 100" | ||
| fill="none" | ||
| stroke="#D85A30" | ||
| stroke-width="4" | ||
| stroke-dasharray="24 24"></path> | ||
| </svg> | ||
| ``` | ||
|
|
||
| #### CSS | ||
|
|
||
| We set a `path-length` value on the `<path>`: | ||
|
|
||
| ```css live-sample___basic-path-length | ||
| path { | ||
| path-length: 500; | ||
| } | ||
| ``` | ||
|
|
||
| #### Results | ||
|
|
||
| {{EmbedLiveSample("basic-path-length", "100%", "250")}} | ||
|
|
||
| Setting a large `path-length` value results in the dashes becoming smaller and more frequent. | ||
|
|
||
| ### Animating `path-length` | ||
|
|
||
| One major advantage of making `path-length` available as a CSS property is that you can apply standard CSS functionality such as [animations](/en-US/docs/Web/CSS/Guides/Animations) and [transitions](/en-US/docs/Web/CSS/Guides/Transitions) to it. This example builds on the previous one, showing how to animate a `path-length` with a CSS animation. | ||
|
|
||
| #### HTML and SVG | ||
|
|
||
| This example includes the same SVG `<path>` as the previous one. In addition, it includes an [`<input type="range">`](/en-US/docs/Web/HTML/Reference/Elements/input/range) element that can be used to change the value of `path-length` applied to the `<path>` at runtime. We also include an {{htmlelement("output")}} element to display the current slider value. | ||
|
|
||
| ```html live-sample___path-length-animation | ||
| <div> | ||
| <label for="path-slider">Adjust path-length</label> | ||
| <input type="range" id="path-slider" min="0" max="800" value="200" /> | ||
| <output>200</output> | ||
| </div> | ||
| ``` | ||
|
|
||
| #### CSS | ||
|
|
||
| On the {{cssxref(":root")}} element, we define a [CSS custom property](/en-US/docs/Web/CSS/Reference/Properties/--*) called `--path-length` and give it an initial value of `200`. We then set the `<path>` element's `path-length` value to the `--path-length` property, and set an {{cssxref("animation")}} on it that runs an infinite number of times and alternates between forwards and backwards. | ||
|
|
||
| ```css live-sample___path-length-animation | ||
| :root { | ||
| --path-length: 200; | ||
| } | ||
|
|
||
| path { | ||
| path-length: var(--path-length); | ||
| animation: path-length-anim 2s alternate infinite ease-in-out; | ||
| } | ||
| ``` | ||
|
|
||
| ```css hidden live-sample___path-length-animation | ||
| div { | ||
| position: fixed; | ||
| bottom: 0; | ||
| left: 0; | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
| ``` | ||
|
|
||
| Next, we define the {{cssxref("@keyframes")}} block for the animation — it animates the `path-length` property between the `--path-length` value and the `--path-length` value multiplied by `1.5`. | ||
|
|
||
| ```css live-sample___path-length-animation | ||
| @keyframes path-length-anim { | ||
| from { | ||
| path-length: var(--path-length); | ||
| } | ||
|
|
||
| to { | ||
| path-length: calc(var(--path-length) * 1.5); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### JavaScript | ||
|
|
||
| We start our script by grabbing references to the `<input type="range">`, `<output>`, and `:root` elements. | ||
|
|
||
| ```js live-sample___path-length-animation | ||
| const slider = document.querySelector("input"); | ||
| const output = document.querySelector("output"); | ||
| const rootElem = document.querySelector(":root"); | ||
| ``` | ||
|
|
||
| Next, we add an `input` event handler to the range slider so that, when its value is changed, the `<output>` element's `textContent` and the value of the `--path-length` custom property are set to equal the slider's new value. | ||
|
|
||
| ```js live-sample___path-length-animation | ||
| slider.addEventListener("input", () => { | ||
| output.textContent = slider.value; | ||
| rootElem.style.setProperty("--path-length", slider.value); | ||
| }); | ||
| ``` | ||
|
|
||
| #### Results | ||
|
|
||
| {{EmbedLiveSample("path-length-animation", "100%", "250")}} | ||
|
|
||
| Adjust the slider, and note how larger values result in a smaller dash size. | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - SVG {{SVGAttr("pathLength")}} attribute | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.