Skip to content

Instantly share code, notes, and snippets.

@tistre
Created July 23, 2026 10:26
Show Gist options
  • Select an option

  • Save tistre/daa797beb4626452e06e3ff2c998f447 to your computer and use it in GitHub Desktop.

Select an option

Save tistre/daa797beb4626452e06e3ff2c998f447 to your computer and use it in GitHub Desktop.
Styling an SVG icon with “use” and CSS custom properties
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<p>SVG via <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/use">“use”</a>, can be styled:</p>
<svg viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg" style="--circle-fill: blue; --circle-stroke: black;">
<use href="circle.svg#root"></use>
</svg>
<p>SVG via “img”, cannot be styled (?):</p>
<img src="circle.svg"/>
</body>
</html>
@tistre

tistre commented Jul 23, 2026

Copy link
Copy Markdown
Author

Looks like this:
browser-screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment