I was wondering if it’s possible to change the color of a SVG image/icon/logo in an inline html <img> tag, using style="…"
Here’s part of my code, it’s a button and I want the logo (only the SVG) to be the color indicated
<a href="#" class="nav-link btn btn-outline-secondary d-flex border-0 w-100" style="color:#39384A;" data-toggle="tooltip" data-placement="right" title="Discord">
<img class="m-auto" src="https://www.svgrepo.com/show/353655/discord-icon.svg" style="color:#39384A;">
</a>
As you can see, the color doesn’t change, it remains the color of the SVG file.
I need it to be inline since I don’t have access to the CSS sheet to change the CSS of certain tags and classes (not my website, customization is limited)
thanks!
2
Answers
you have to Embed the SVG directly in the HTML to get access of attributes of svg and change the color of it
You cannot change the color of an external SVG file directly through the
style
attribute of an<img>
tag.However, you can achieve this by embedding the SVG directly in the HTML and applying the desired color via CSS.
Here’s how you might do so:
Here’s your modified code with the SVG content inline and styled:
Note the
style="fill:#39384A;"
which will change the SVG to the specified color.