CKTIS / CSS
stroke-dasharray — stroke dash pattern
The CSS stroke-dasharray property defines the repeating pattern of dashes and gaps along an SVG stroke. It controls their lengths, while none restores a continuous stroke.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate; usage example verification passed
Syntax
/* CSS Fill and Stroke Level 3: # denotes a comma-separated list. */
stroke-dasharray: none | <length-percentage>#;
/* SVG 2: none or a list of lengths, percentages, or unitless numbers. List items may be separated by commas, whitespace, or both. */
stroke-dasharray: 12px 8px;stroke-dasharray controls dashing on SVG shapes and text, not CSS borders. It is inherited; its initial value, none, means a continuous stroke. To see the effect, set a visible stroke and a positive stroke-width.
The list starts with a dash length, then a gap length, and repeats that sequence. 12px 8px means a dash of length 12 and a gap of length 8. An odd-length list is duplicated: 5 3 2 behaves like 5 3 2 5 3 2. The pattern restarts at each subpath.
SVG accepts unitless numbers, lengths, and percentages, with spaces or commas as separators. Unitless numbers represent SVG user units. Percentages refer to the normalized diagonal of the SVG viewport, not the path length. Negative values are invalid; an all-zero list behaves like none.
stroke-dashoffset shifts the pattern's starting position, whereas stroke-linecap changes the appearance of dash ends. The example uses butt so that caps do not extend the visible dashes.
Examples
<!doctype html>
<meta charset="utf-8">
<title>stroke-dasharray</title>
<style>
line {
stroke: black;
stroke-width: 4px;
stroke-linecap: butt;
stroke-dasharray: 12px 8px;
}
</style>
<svg xmlns="http://www.w3.org/2000/svg" width="220" height="40" viewBox="0 0 220 40" role="img" aria-label="Dashed line">
<line x1="10" y1="20" x2="210" y2="20" />
</svg>Result
A horizontal black line with 10 dashes, each 12 units long, separated by 8-unit gaps; the final 8 units are also a gap.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.