Is there a way in SVG to re-use part of a <path>
while keeping the other parts of the <path>
intact?
I'm trying to build a static SVG file (no HTML or JS allowed, although can leverage external CSS) that has 20+ instances of a variable-width horizontal curly brace that looks like this:
All the instances are the same height but each one has a different width, which means that the arcs (a
) are identical but the initial position and horizontal lines (h
) will be different for each one. This also means that I can't use <use>
and then scale each instance horizontally, because scaling would result in stretched-out arcs which look bad. (BTW, while researching this I learned about vector-effect="non-scaling-stroke"
which, if combined with <use>
would be a perfect solution if there were no curves involved.)
I know I can use <use>
and override the d
attribute in each one, but is there a better way than cloning the same d
attribute 20+ times and editing the h
values inside each one? An ideal solution would be to be able to re-use sub-paths, e.g. d="${left} h 100 ${middle} h 100 ${left}"
which I could trivially do if JS were allowed, but alas I can't use script in this context.
Is there a way to do something like below (in SVG; I know I could do it in HTML) where paths each pick up where the last one ended?
<use href="#left">
<path d="h 200">
<use href="#mid">
<path d="h 200">
<use href="#right">
If not, is there another way to do what I'm looking for?
Here's the SVG I have now: (https://codepen.io/justingrant/pen/rNLqQRo)
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3000 500" width="3000" height="500" fill="none" stroke-width="5" stroke="green" >
<path d="m 80,80
a 30 30 0 0 1 30,-30
h 100
a 30 30 0 0 0 30,-30
a 30 30 0 0 0 30,30
h 100
a 30 30 0 0 1 30,30"/>
<path d="m 500,80
a 30 30 0 0 1 30,-30
h 40
a 30 30 0 0 0 30,-30
a 30 30 0 0 0 30,30
h 40
a 30 30 0 0 1 30,30"/>
</svg>
I know I could run the raw code through a build step or pre-processor, but I'd prefer a native SVG solution before hacking together something like that.