W3docs

CSS stroke-dashoffset Property

How to use the stroke-dashoffset CSS property to specify where the dash of the stroke should begin. Read about the property and see the values with examples.

The stroke-dashoffset property is a presentation attribute which defines the location along an SVG path where the dash of a stroke will begin.

CSS rules override presentation attributes. Inline styles take precedence over both.

Info

The stroke-dashoffset property can be used as both a CSS property and a presentation attribute. It can be applied to any element but can have an effect only on the following elements: <altGlyph>, <circle>, <ellipse>, <path>, <line>, <polygon>, <polyline>, <rect>, <text>, <textPath>, <tref>, and <tspan>.

Info

"Px" or "em" units are not required.

Initial Value0
Applies toShapes and text content elements.
InheritedYes.
AnimatableYes.
VersionSVG 1.1 Specification
DOM SyntaxObject.strokeDashoffset = 5;

Syntax

CSS stroke-dashoffset syntax

stroke-dashoffset: length | percentage | initial | inherit;

Example of the stroke-dashoffset property:

The stroke-dashoffset value shifts the starting point of the dash pattern along the path.

CSS stroke-dashoffset code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Stroke-dashoffset property example</h2>
    <svg viewBox="-3 0 33 10" >
      <line x1="0" y1="1" x2="30" y2="1" stroke="#1c87c9" />
      <line x1="0" y1="3" x2="30" y2="3" stroke="#ccc"
        stroke-dasharray="4 1" />
      <line x1="0" y1="5" x2="30" y2="5" stroke="#8ebf42"
        stroke-dasharray="3 1"
        stroke-dashoffset="3" />
      <line x1="0" y1="7" x2="30" y2="7" stroke="#FF0000"
        stroke-dasharray="3 1"
        stroke-dashoffset="-3" />
      <line x1="0" y1="9" x2="30" y2="9" stroke="#666"
        stroke-dasharray="3 1"
        stroke-dashoffset="1" />
      <path d="M0,5 h-3 M0,7 h3 M0,9 h-1" stroke="#000"/>
    </svg>
  </body>
</html>

Result

CSS stroke-dashoffset values list

Values

ValueDescription
lengthSets the length of the property. "Px" or "em" units are not required.
percentageThe property is specified by percentage.
initialMakes the property use its default value.
inheritInherits the property from its parents element.

Practice

Practice

What is the purpose of the stroke-dashoffset CSS property and how is it used?