I am facing an issue where I have a SVG image whose color attribute I've set to currentColor
, but despite that I'm not able to control in my HTML.
Image SVG:
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 200 200" style="enable-background:new 0 0 200 200;" xml:space="preserve">
<rect x="0" y="0" fill="currentColor" width="200" height="200"/> // I'm trying to replace this color
<path fill="#FFFFFF" d="M133.17,79.76c-0.92,0-1.84, ..."/> // This path should always be white
</svg>
React code
import sdgHeartIcon from '.myImage.svg'
export default function MyComponent() {
return (
<img src={sdgHeartIcon} style={{ fill: 'red' }} />
)
}
I've also tried setting backgroundColor
and color
attributes. If I modify the fill
attribute within the SVG image directly, then that works, but I need to be setting it dynamically.