大网数据广告活动
Web 标准与前端开发

pathLength

· 52CE 我爱测

The **`pathLength`** attribute lets authors specify a total length for the path, in user units. This value is then used to calibrate the browser's distance calculations with those of the author, by scaling all distance computations using the ratio `pathLength` / (_computed value

The pathLength attribute lets authors specify a total length for the path, in user units. This value is then used to calibrate the browser's distance calculations with those of the author, by scaling all distance computations using the ratio pathLength / (computed value of path length).

This can affect the actual rendered lengths of paths; including text paths, animation paths, and various stroke operations. Basically, all computations that require the length of the path. stroke-dasharray, for example, will assume the start of the path being 0 and the end point the value defined in the pathLength attribute.

You can use this attribute with the following SVG elements:

  • circle
  • ellipse
  • line
  • path
  • polygon
  • polyline
  • rect

[!NOTE] The pathLength attribute also has a CSS property counterpart: path-length. When both are specified, the CSS property takes priority.

circle

For circle, pathLength lets authors specify a total length for the circle, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

ellipse

For ellipse, pathLength lets authors specify a total length for the ellipse, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

line

For line, pathLength lets authors specify a total length for the line, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

path

For path, pathLength lets authors specify a total length for the path, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

polygon

For polygon, pathLength lets authors specify a total length for the shape, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

polyline

For polyline, pathLength lets authors specify a total length for the shape, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

rect

For rect, pathLength lets authors specify a total length for the rectangle, in user units.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

Example

html,
body,
svg {
  height: 100%;
}
<svg viewBox="0 0 100 60" xmlns="http://www.w3.org/2000/svg">
  <style>
    path {
      fill: none;
      stroke: black;
      stroke-width: 2;
      stroke-dasharray: 10;
    }
  </style>

  
  <path d="M 0,10 h100" />

  
  <path d="M 0,20 h100" pathLength="90" />

  
  <path d="M 0,30 h100" pathLength="50" />

  
  <path d="M 0,40 h100" pathLength="30" />

  
  <path d="M 0,50 h100" pathLength="10" />
</svg>

Example

Specifications

See also

  • CSS path-length property

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。