{"id":236645,"date":"2016-01-18T14:24:06","date_gmt":"2016-01-18T21:24:06","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=236645"},"modified":"2022-07-13T16:15:35","modified_gmt":"2022-07-13T23:15:35","slug":"stroke-dasharray","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/s\/stroke-dasharray\/","title":{"rendered":"stroke-dasharray"},"content":{"rendered":"\n
The It’s a ll a little confusing because As such, you’ll want to remember:<\/p>\n\n\n\n First off, this property is specifically designed to work with SVG elements. Which ones? Basically any SVG shape or text element:<\/p>\n\n\n\n Values can be separated either by spaces or commas \u2014 your choice!<\/p>\n\n\n\n Unitless values are likely the most common choice, as it is generally with SVG values. They become length units that are relative to the coordinate system set up by the The mind-bending thing about If we set one value<\/strong>, both the dash length and gap length take that value and repeat the pattern.<\/p>\n\n\n\nstroke-dasharray<\/code> property in CSS sets the length of dashes in the stroke of SVG shapes. More specifically, it sets the length of a pattern of alternating dashes and the gaps between them<\/em>.<\/p>\n\n\n\n\n\n\n\n
path {\n stroke-dasharray: 5; \/* dashes and gaps are both 5 units long *\/\n}<\/code><\/pre>\n\n\n\n
stroke-dasharray<\/code> is a SVG presentational attribute (e.g.
<path stroke-dasharray=\"5\" ... \/><\/code>) that can also be used as a CSS property in your stylesheet, like this:<\/p>\n\n\n\n
<path stroke-dasharray=\"5\" ... \/><\/code><\/li>
<path style=\"stroke-dasharray: 5;\" ... \/><\/code><\/li><\/ul>\n\n\n
Where to use it<\/h3>\n\n\n
<altGlyph><\/code><\/li>
<circle><\/code><\/li>
<ellipse><\/code><\/li>
<path><\/code><\/li>
<line><\/code><\/li>
<polygon><\/code><\/li>
<polyline><\/code><\/li>
<rect><\/code><\/li>
<text><\/code><\/li>
<textPath><\/code><\/li>
<tref><\/code><\/li>
<tspan><\/code><\/li><\/ul>\n\n\n
Syntax<\/h3>\n\n\n
stroke-dasharray: none | <dasharray> | inherit;<\/code><\/pre>\n\n\n\n
none<\/code><\/li>
Values<\/h3>\n\n\n
\/* Keyword values *\/\nstroke-dasharray: none;\nstroke-dasharray: inherit;\n\n\/* Length values *\/\nstroke-dasharray: 2\nstroke-dasharray: 2.5\nstroke-dasharray: 2em\nstroke-dasharray: 15%\n\n\/* Two-value syntax *\/\nstroke-dasharray: 2 4\nstroke-dasharray: 2 4% 5 4%\nstroke-dasharray: 2em 4 6 8<\/code><\/pre>\n\n\n\n
viewBox<\/code>.<\/p>\n\n\n
Pattern behavior<\/h3>\n\n\n
stroke-dasharray<\/code> is that it’s merely a set of length values, but its setting both the length of the dashes and gaps between them.<\/p>\n\n\n\n