Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

stroke-dashoffset — shifting a dash pattern

The stroke-dashoffset property selects where within a repeating pattern of dashes and gaps an SVG stroke begins. It changes the dash phase, not the position or length of the path.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate; usage example verification passed

Syntax

stroke-dashoffset: <length-percentage>;
/* SVG 2 also permits <number>. */
stroke-dashoffset: 0;
stroke-dashoffset: 10px;
stroke-dashoffset: -10px;
stroke-dashoffset: 5%;

stroke-dashoffset specifies the distance into the repeating pattern defined by stroke-dasharray at which path dashing starts. Its initial value is 0; it is inherited and applies to strokes on SVG shapes and text. Without a dash pattern, changing the offset has no visible effect. It is not equivalent to transform or the border properties.

Positive and negative values are allowed. A positive offset skips the beginning of the pattern; a negative offset shifts its phase in the opposite direction. CSS Fill and Stroke specifies <length-percentage>, while SVG 2 additionally permits <number> in user units. Percentages refer to the normalized diagonal of the SVG viewport, not the path length: sqrt((width² + height²) / 2). In SVG 2, the pathLength attribute affects interpretation of dash distances.

In the example, stroke-dasharray: 20px 10px creates 20-unit dashes and 10-unit gaps. The lower stroke has stroke-dashoffset: 10px, so its first visible dash is 10 units long. The geometry remains unchanged.

Examples

<!doctype html>
<meta charset="utf-8">
<title>stroke-dashoffset</title>
<style>
  path {
    fill: none;
    stroke: black;
    stroke-width: 4px;
    stroke-linecap: butt;
    stroke-dasharray: 20px 10px;
  }
  .shifted { stroke-dashoffset: 10px; }
</style>
<svg xmlns="http://www.w3.org/2000/svg" width="160" height="70" viewBox="0 0 160 70">
  <path d="M 20 20 H 140" />
  <path class="shifted" d="M 20 50 H 140" />
</svg>

Result

Two horizontal black dashed strokes. The upper stroke begins with a 20-unit dash; the lower stroke begins with a 10-unit dash, followed by a 10-unit gap. Neither path moves.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources