How SVG recoloring works
A CSS mask uses the SVG’s transparency as a stencil. The element’s background-color fills that stencil, so original fills and strokes become one controllable color. This works well for icons, logos, and interface symbols.
.icon {
color: #818cf8;
background-color: currentColor;
mask-image: url("data:image/svg+xml,%3Csvg ... %3E");
mask-size: contain;
}Use currentColor for icon systems
With currentColor, the mask follows the element’s inherited color. One encoded asset can then handle default, hover, disabled, and dark-mode states without generating another SVG.
When not to use a mask
Masks intentionally flatten an SVG to one color. Keep a multicolor illustration as a CSS background, external image, or inline SVG element. Inline SVG is also the better option when individual paths need separate colors or animation.
Frequently asked questions
How do I change an SVG color with CSS?
Use the SVG as a mask-image and set background-color to currentColor, a hex color, or a CSS variable. The mask supplies the shape while CSS supplies the color.
Why does a CSS mask make the SVG one color?
CSS masks read the SVG alpha channel rather than its original fills and strokes. Every visible part receives the element’s background color.
Can the SVG follow the text color?
Yes. Keep background-color: currentColor and the icon inherits the color property from itself or its parent.
Is the SVG uploaded?
No. Encoding, CSS generation, and preview all run locally in your browser.
Need the SVG’s original colors? Use the SVG to CSS converter for background-image output. For React, HTML, favicons, and raw data URIs, use the main SVG Encoder.