I have the following svg image in my html file:
<img class="svg" src="my-image-link.svg">
Now, I am trying to change the color using this css code:
.svg path {
fill: black;
}
However, nothing changes. What is the correct way to change the color of an svg image's path using css? Thanks!
You can't change the color of an image that way. If you load SVG as an image, you can't change how it is displayed using CSS or Javascript in the browser. If you want to change your SVG image, you have to load it using <object> , <iframe> or using <svg> inline.
The fill property is a presentation attribute used to set the color of a SVG shape.
You have to use an inline SVG, where the path element is inside the HTML, as opposed to linking to an external SVG.
Example: https://jsfiddle.net/fznuckb0/1/
.path-name {
fill: tomato;
fill-rule: evenodd;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With