Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Properties for Special Contexts

The stroke-dasharray property

Reference for the CSS stroke-dasharray property: turn SVG strokes into dashed or dotted lines with dash and gap lengths, patterns, examples and tips.

The stroke-dasharray property turns a solid SVG stroke into a repeating pattern of dashes and gaps. You give it a list of lengths: the first is a dash, the second a gap, the third a dash again, and so on, repeating along the whole outline.

Together with stroke-dashoffset it also powers the well-known "line drawing" animation.

CSS
path {
  stroke: black;
  stroke-dasharray: 10 5;
}

Try it

Dash patterns

The 0 12 pattern has zero-length dashes; with stroke-linecap: round each one becomes a dot.

Syntax

CSS
stroke-dasharray: none | [ <length-percentage> | <number> ]+#;

Lengths can be separated by spaces or commas.

  • Initial value: none
  • Applies to: SVG shapes and text content elements
  • Inherited: yes
  • Animatable: yes, when both lists have the same number of items
  • Computed value: none, or a list of absolute lengths or percentages

Values

Value Description
none A solid stroke.
One number, 6 Dashes and gaps are both 6 units long.
Several numbers, 20 10 Alternating dash, gap, dash, gap.
Odd count, 25 10 5 The list is repeated once to make an even count: 25 10 5 25 10 5.

Usage notes

  • Line-drawing effect. Set the dash and the gap to the path length, then animate stroke-dashoffset from that length to zero. Measure the length with path.getTotalLength() or set pathLength="1" on the element and use 1 in CSS.
  • Dots need zero-length dashes plus stroke-linecap: round (or square). With the default butt caps, zero-length dashes are invisible.
  • Negative values are invalid, and a list whose values are all zero is treated as a solid line.
  • Rectangles and circles start their pattern at a fixed point (the top-left for <rect>, the rightmost point for <circle>), which may produce an uneven join. Adjust the offset or numbers.
  • Scaling. Dash lengths scale with the drawing, just like stroke-width.

Browser support

Supported in every major browser.