Questions tagged [stroke-dasharray]

The SVG stroke-dasharray attribute controls the pattern of dashes and gaps used to stroke paths.

The stroke-dasharray attribute controls the pattern of dashes and gaps used to stroke paths.

As a presentation attribute, it also can be used as a property directly inside a CSS stylesheet

It's a list of comma and/or white space separated s and s that specify the lengths of alternating dashes and gaps. If an odd number of values is provided, then the list of values is repeated to yield an even number of values. Thus, 5,3,2 is equivalent to 5,3,2,5,3,2. Example

Source code Output result

<line stroke-dasharray="5, 5"              x1="10" y1="10" x2="190" y2="10" />
<line stroke-dasharray="5, 10"             x1="10" y1="30" x2="190" y2="30" />
<line stroke-dasharray="10, 5"             x1="10" y1="50" x2="190" y2="50" />
<line stroke-dasharray="5, 1"              x1="10" y1="70" x2="190" y2="70" />
<line stroke-dasharray="1, 5"              x1="10" y1="90" x2="190" y2="90" />
<line stroke-dasharray="0.9"               x1="10" y1="110" x2="190" y2="110" />
<line stroke-dasharray="15, 10, 5"         x1="10" y1="130" x2="190" y2="130" />
<line stroke-dasharray="15, 10, 5, 10"     x1="10" y1="150" x2="190" y2="150" />
<line stroke-dasharray="15, 10, 5, 10, 15" x1="10" y1="170" x2="190" y2="170" />
<line stroke-dasharray="5, 5, 1, 5"        x1="10" y1="190" x2="190" y2="190" />

Source:

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray

66 questions
16
votes
1 answer

SVG line stroke-dasharray not print properly to PDF

Print line with stroke-dasharray to PDF create different behavior, please look at the image here. Picture A, a screenshot I took directly from the browser (Chrome). Picture B is the printed PDF from the same page. Notice the difference in Picture B,…
damcedami
  • 161
  • 6
14
votes
2 answers

SVG stroke-dasharray offset not consistent

I have a series of circles with borders comprised of smaller circles which I will call 'dots'. I am then animating the circles by rotating them with CSS3's transform, each by either 5 or 15 degrees (alternating) more than the last starting with the…
Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
7
votes
1 answer

SVG - It is possible to add stroke-dasharray Gradient or transparent form one side

I have created an SVG animation in which I am allowing stroke-dasharray to move. Is it possible that I can add a gradient to the tail of stroke-dasharray and keep one side transparent as you can see in the example? .svg-main { width:…
Figar Ali
  • 826
  • 1
  • 9
  • 17
5
votes
1 answer

svg rectangle with radius, dash-array and dash-offset

I am trying to create a rectangle in svg with a border / stroke at the top and bottom and with rounded corners by using a radius (rx, ry). By using the css property "dasharray: width, height" it is possible to style only the top and the bottom with…
joost2076
  • 101
  • 2
  • 8
4
votes
1 answer

SVG - stroke-dasharray with percentage units doesn't work as expected

I think I don't quite understand something here. Percentage units in stroke-dasharray are realtive to what? I was thinking relative to the SVG viewbox, but I was probably wrong. My problem: I have an SVG with the width of 320px and the height of…
3
votes
1 answer

SVG stroke-dashoffset working strangely on IOS (safari and chrome)

I've been working on an animation that shows a single GPS track being drawn from start to end. The following works correctly on macOS chrome and safari, and android chrome. When trying this on my iPad (safari, chrome, firefox), I see that the track…
SanderDN
  • 496
  • 6
  • 19
3
votes
1 answer

How to change the "starting point" of the stroke-dasharray in a SVG image?

I want to animate a custom logo like a typical progress circle (e.g. for percentage). Therefore I created a circle with stroke and set a clip-path to the svg logo. I'm nearly done, but i need to change the starting point of the stroke animation from…
2
votes
2 answers

Change start point of svg stroke animation

I have svg stroke animation https://codesandbox.io/s/magical-hill-r92ong But it's starts from bottom-right position, can i start it from upper center like on screenshot (red dot) ? I try to set stroke-dashoffset with negative value it's helps to set…
source2003
  • 23
  • 2
2
votes
1 answer

How to calculate exact stroke-dasharray values for seamless animation

I am trying to animate the stroke-dashoffset property of a svg element as following const svg = document.querySelector("svg"); //const svgns = "http://www.w3.org/2000/svg" var ln = document.querySelector('.ln'); var path =…
smpa01
  • 4,149
  • 2
  • 12
  • 23
2
votes
2 answers

Pie chart using circle element

I am trying to create a pie chart using circle element in svg. I am able to fill values to 60%, 30% and 10% but all the circle starting from same position. How can I make next circle start from where previous one ended? svg { transform:…
Imad
  • 7,126
  • 12
  • 55
  • 112
2
votes
2 answers

How can I achieve a percentage-based line length on an SVG with stroke-dasharray?

I'm trying to achieve a percentage-based border-like effect on an SVG rect element, like the one shown in the image below. I've been advised that I need to use stroke-dasharray in order to do this, but despite playing around with a JSFiddle, I've…
Jimmy Rowe
  • 31
  • 4
2
votes
0 answers

Stroke-dasharray and stroke-dashoffset behaving weirdly on circle in Safari

I'm using a element with stroke-dasharray and stroke-dashoffset to draw an indicator for the focused element of a donut chart, and in Safari it is not coming out right. The outer pies are s which work fine in all browsers, but as I…
Charlotte Dann
  • 298
  • 2
  • 10
2
votes
2 answers

stroke-dasharray can't bind with angular 6

I used this Chart with angular 6 , I faced the some conflict on this chart, i try to bind data , but i cant do that, its not working correctly, This stroke-dasharray="5, 100" to I replaced this one…
core114
  • 5,155
  • 16
  • 92
  • 189
2
votes
0 answers

SVG pointer-events and stroke-dasharray

In the next example I'm drawing an ellipse with no fill and a stroke-dasharray. The pointer-events is set to visibleStroke or stroke. When I mouse over the stroke the circle inside should change it's fill and the stroke: ellipse:hover ~ circle { …
enxaneta
  • 31,608
  • 5
  • 29
  • 42
2
votes
1 answer

Border styling of a circle to be ticks

I have a circle that has dotted borders. However, instead of dots the border should be more like vertical dashes. Is there a way to make the border exactly the same as the design (the vertical dashes one not the thick solid line) with css? I want to…
john
  • 157
  • 2
  • 12
1
2 3 4 5