Search code examples
csssvgscopestyles

Is there a way to isolate SVG styles?


<svg>
    <defs>
        <style>
             .test {
                 fill: red;
             }
        </style>
    </defs>
    <circle class="test"></circle>
</svg>
<div class="test">test</div>

How to make works class .test only for SVG element. Is there a way to isolate SVG classes/styles?


Solution

  • Yes, by putting the SVG in the shadowDOM of a W3C standard Web Component

    supported in all modern Browsers.