CSS Portal

CSS stroke-dasharray Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The stroke-dasharray property controls how a stroked path is broken up into a repeating pattern of painted segments and gaps, turning a continuous outline into dashed or dotted lines. Rather than altering the geometry of the shape itself, it changes the way the stroke is rendered along the path: the visual rhythm of dashes and spaces is applied along the path’s length and repeats as necessary. This property is often used together with stroke-dashoffset to shift the pattern along the path, which is useful for aligning dashes or creating motion effects.

Because the pattern is rendered along the path, the final appearance depends on how the stroke interacts with line caps and joins and on the stroke’s thickness and color. For example, the shape of the ends of each dash is determined by stroke-linecap, and thicker strokes created by stroke-width will make the pattern read differently at a given scale. The stroked color set by stroke is applied to the dashes only; gaps remain transparent. Transformations and coordinate-space considerations can also affect how the dash pattern scales and repeats—behaviors that may be influenced by properties such as vector-effect.

In practical use, stroke-dasharray is a versatile stylistic tool: designers use it to convey emphasis, hierarchy, or a hand-drawn look, and developers commonly animate the perceived drawing of a path by manipulating dash-related properties to reveal or hide parts of the stroke. The repeating nature of the pattern means that its relationship to the total path length matters visually: short paths may cut a pattern off mid-sequence, while long paths will show many repeats. Because the property only affects rendering, it is compatible with any stroked SVG geometry and integrates cleanly with animations and scripts that adjust stroke rendering over time.

Definition

Initial value
none
Applies to
inline boxes and SVG shapes
Inherited
Yes
Computed value
as specified
Animatable
as repeated list of length, percentage or calc
JavaScript syntax
object.style.strokeDasharry

Syntax

stroke-dasharray = none | [ <length-percentage>

Values

  • noneNo dashing: the stroke is drawn continuously.
  • <length-percentage>Specifies a dashing pattern to use. Each <length-percentage> value represents the length of the next dash or gap (beginning with the first dash and alternating from there) of the stroke. The pattern repeats over the length of the stroke. (If the number of values is odd, the pattern behaves as if it was duplicated to yield an even number of values.) The dashing pattern is reset and begins anew at the start of each subpath.

Example

<svg width="300" height="120">
<!-- Dashed line -->
<line x1="20" y1="30" x2="280" y2="30" class="dashed-line" />

<!-- Dotted circle -->
<circle cx="150" cy="85" r="35" class="dotted-circle" />
</svg>
.dashed-line {
  stroke: #0077cc;
  stroke-width: 4;
  stroke-dasharray: 12 6;
}

.dotted-circle {
  fill: none;
  stroke: #e63946;
  stroke-width: 4;
  stroke-dasharray: 2 10;
  stroke-linecap: round;
}

Browser Support

The following information will show you the current browser support for the CSS stroke-dasharray property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 28th December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!