Search code examples
google-chromesvgtransformchromium

SVG translate seems to behave different in Chrome/Chromium


https://jsfiddle.net/Lpfa9umq/

Code:

<svg>
    <symbol>
        <circle id="circle1" cx="50" cy="50" r="20" stroke="black" stroke-width="1" />
        <circle id="circle2" cx="25" cy="25" r="10" stroke="red" fill="red" stroke-width="1" />
    </symbol>
</svg>
<svg width="100" height="100">
    <use xlink:href="#circle1" />
    <svg width="50" height="50" transform="translate(20, 10)">
        <use xlink:href="#circle2" />
    </svg>
</svg>

The transform attribute is applied in Firefox, but not in Chrome/Chromium, why? Am I using it wrong?


Solution

  • <svg> within <svg> is confusing the browser. Instead use <g> tag.

    <g transform="translate(20, 10)">
        <use xlink:href="#circle2" />
    </g>