SVG Icon Color Not Changing With CSS: Fix the fill and stroke

If you set color on an SVG icon with CSS and nothing changes, it's usually because the color value is already hardcoded in the icon file as an attribute like fill="#3b82f6". CSS color doesn't automatically override that value. This article explains why inheritance breaks down and how to change the fill and stroke values inside the file itself.
Summary ① SVG
fill/strokeattributes are not automatically tied to CSScolor. They inherit it only whenfill: currentColoris explicitly set in the SVG or CSS. ② An SVG loaded with an<img>tag receives no CSS from the page, so you can't change its color that way in the first place. ③ The most reliable method is to replace the fill/stroke values inside the SVG code with the color code you want.
The Problem
It's common to download an icon set, add it to your site, and set .icon { color: red; } in CSS to change the color on hover, only to see the icon stay exactly the same. When you open it in DevTools, you find a color value already baked into each element, like <path fill="#3b82f6">.
The reason is that SVG fill/stroke are paint properties separate from text color. The initial value of fill is not currentColor but black, so for it to inherit the parent's color, the SVG has to explicitly declare fill="currentColor". Most downloaded icons have a specific color (blue, for example) already hardcoded as the fill value by the original author, so there's no room for another color to get in.
There's a more fundamental problem when you load the icon as an image tag, like <img src="icon.svg">. The browser treats an SVG loaded with <img> as a completely separate document, so the parent page's CSS can't pass down even currentColor. In this case, no amount of CSS tweaking will change the color.
The Fix
To fix it with CSS alone, without touching the original SVG code, first paste the icon directly into the page HTML as <svg>...</svg> instead of <img> (inline SVG). Then delete the fill="#3b82f6" attribute on each element or change it to fill="currentColor". Only then will the CSS .icon { color: red; } inherit and apply.
If you have one or two elements, you can edit them by hand. But if there are several different fill values mixed together (for example, when the border color and fill color differ) or you have a lot of icons, changing them one by one is tedious. In that case, including when you use the icons as <img> tags, it's more reliable to replace the fill/stroke attribute values in the SVG code itself with the color you want all at once.
Before you check with our tool, understanding how it works when you do it manually in a text editor makes it easier to verify the result. Find the fill="..." strings in the SVG code and replace them with the color code you want. To change the lines (borders) too, change the stroke="..." values as well. Just don't touch attributes whose value is none or transparent, since those mean "no paint" to begin with.
Paste your SVG code, pick a color, and swap it right away.

Common Pitfalls
| Symptom | Cause |
|---|---|
| I changed it with the tool, but it doesn't show on the live site | An SVG loaded with an <img> tag only updates when you replace the file itself. Download the changed code and overwrite the original file |
| Only the line (border) color stays the same | Unless you turn on the "Also change stroke color" checkbox, stroke attributes are left untouched |
| Only some paths don't change color | Those elements either had no fill attribute to begin with or have a value of none. They had no color originally, so this is expected |
| A gradient turns into a solid color | Values that referenced a gradient, like fill="url(#gradientA)", are also string-replaced, so they get overwritten with a solid color |
CSS .icon { fill: red } doesn't work | If the icon has an inline style="fill:...", it has higher priority than external CSS and wins |
The Takeaway
SVG icon colors usually don't change with CSS because the fill/stroke attributes set the color directly and break color inheritance. With <img> tags, it's because CSS can't get inside at all. You can switch to inline SVG and use fill: currentColor, but if you want to change several color values to the color you want all at once, replacing the values in the code is faster.
Paste your SVG code, pick a color, and swap it right away.
Frequently Asked Questions
Can I change the color of an icon used with an <img> tag?
An SVG loaded with <img> doesn't receive page CSS, so you can't change it with CSS. Instead, change the fill/stroke values in the SVG file itself to the color you want, then swap in that file as the <img> source.
Does it support icons that use gradients or patterns?
Because it replaces the values themselves with new colors, anything that referenced a gradient definition, such as fill="url(#gradientA)", also becomes the solid color you choose. If you want to keep the gradient effect, you need to edit the color values in the gradient defined in <defs> directly.
Why do only some pieces of an icon not change color?
Those elements either have no fill attribute to begin with or have a value of none/transparent. They're the parts that were never filled (empty space, outline-only pieces), so there's nothing to recolor.
This article was adapted from our Korean original. Read the Korean original