You cut a dashed SVG outline into two pieces so you can style them separately. The pieces still meet at exactly the same point, but the dash over the cut gets longer. The next dash moves too.
A dashed stroke starts its pattern at the beginning of each subpath. Splitting a path adds a new starting point, so the second piece needs its own dash offset to pick up where the first piece left off.
One line, three renderings
The test uses a 180-unit horizontal path with a 24-unit dash, a 16-unit gap, and butt caps. The cut is at 86 units from the original start. All three rows use the same geometry, viewBox scale, stroke width, dash array, and cap style.
Here are the three cases in a single SVG. The vertical positions separate the rows so you can compare them.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 0 188 64">
<g fill="none" stroke="#1559b1" stroke-width="3"
stroke-linecap="butt" stroke-dasharray="24 16">
<!-- Intact -->
<path d="M 0 12 H 180" />
<!-- Split, same settings -->
<path d="M 0 32 H 86" />
<path d="M 86 32 H 180" />
<!-- Split, corrected -->
<path d="M 0 52 H 86" />
<path d="M 86 52 H 180" stroke-dashoffset="6" />
</g>
</svg>
Where the dash moves
On the intact path, the dash across the cut runs from 80 to 104. At 86, six units of that dash have already been painted. If the second piece starts with an offset of zero, it paints a fresh 24-unit dash from 86 to 110. Because the two painted pieces touch at the cut, they look like one long dash from 80 to 110.
These are the boundaries measured in the rendered comparison. Positions are in SVG units from the original start.
| Rendering | Dash across the cut | Next dash starts at |
|---|---|---|
| Intact | 80–104 | 120 |
| Split, offset 0 | 80–110 | 126 |
| Split, offset +6 | 80–104 | 120 |
Give the second piece the phase at the cut
The dash pattern repeats every 24 + 16 = 40 units. The cut is 86 % 40 = 6 units into that cycle. A positive stroke-dashoffset="6" tells the second path to start six units into the repeated pattern. It paints the remaining 18 units of the dash, then reaches the next gap at 104.
For a path that already has an offset, add the distance to the cut to that offset. You can reduce the result to one cycle to keep the value easy to inspect.
const period = 24 + 16;
const originalOffset = 0;
const distanceToCut = 86;
const phase = originalOffset + distanceToCut;
secondPath.setAttribute(
"stroke-dashoffset",
((phase % period) + period) % period
);
This assumes both pieces follow the original drawing direction and use the same distance scale for dashing. For a curved path, use the length traveled along the curve. If the first piece preserves the original start and geometry and shares the same coordinate system, its getTotalLength() gives you that distance. For a dash array with an odd number of entries, SVG repeats the list to form an even-length cycle before it computes the period.
If the SVG uses pathLength
pathLength changes the distance scale for the dash pattern. Say the original 180-unit path declares pathLength="100". Copying that value to both pieces makes each piece count as 100 dash units, so the drawn dash and gap lengths change.
Keep the original scale by assigning the pieces proportional values. In this example, they are 100 × 86 / 180 ≈ 47.7778 and 100 × 94 / 180 ≈ 52.2222. The distance to the cut is then about 47.7778 on the dash scale, so the second offset is about 7.7778 after wrapping by 40. Keep the fractions in code if you calculate the values dynamically.
There are two details to check in a real icon. An extra M creates a new subpath, so putting both pieces back into a single <path> with a second move command still restarts the pattern. And at a corner, a split replaces the original stroke join with two endpoints. Matching the phase fixes the dash positions, while caps and joins can still change the shape at the seam.
When you review a dashed SVG after splitting it, compare the first dash after the cut with the intact version. If it has moved, check the offset and, when present, how pathLength was carried over.


Top comments (0)