I have a simple external SVG file circles.svg that contains related CSS in <style> tag:
<svg id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMinYMin meet" viewBox="0 0 500 500">
<style type="text/css">
.circle {
fill: green;
}
.use {
fill: blue;
scale: 2;
transform-origin: center;
}
</style>
<circle
id="circle"
class="circle"
cx="250"
cy="250"
r="120"
/>
<use class="use" href="#circle" y="120"/>
</svg>
Then in HTML I reference this SVG file using <svg><use> tags:
<div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500">
<use href="circles.svg#svg"></use>
</svg>
</div>
Chrome renders it as two green intersecting circles, second twice in size than the other. That's the expected behavior. But Firefox renders two black circles identical in size. It means it totally ignores styles.
- Why that happens?
- Is there a way to overcome it, keeping styles inside an external SVG file and referencing with
<svg><use>tags?
UPDATE
I can't create code smaple right here because it requires to upload somewhere svg file. Image upload here doesn't accept svg's. Loading svg from other service (domain) not permitted. So I've created public sandbox to be able to test and play with.



<img src="file.svg"/>in HTML, the same SVG is also showing as intended. The problem is your HTML, not SVG.useelement got it's Y axis position not from CSS but fromyattribute set to 120. But that's minor thing in this case.imgtag as well as withobjecttag gives expected result. But I am frustrated due to svg-use reference problem. Because as far as I know it is the only way pass CSS variables from page to external SVG.