Recoloring SVGs & Generating Exact Dark-Mode CSS Filters

Batch-recolor multi-path SVG icons without broken strokes, or compute exact brightness/sepia/hue-rotate CSS filters for img tags in dark mode.

5 min read · Updated 2026-11-22

Summary

TechniqueWorks on HTML img tagsPreserves multi-color fillsDark-mode friendliness
Inline currentColor / fill editNo (inline <svg> only)Yes — selective hue replacementInstant CSS variable swaps
CSS filter: invert() sepia() ...Yes (HTML img & masks)Monochrome tinting onlySingle CSS class per theme token
CSS mask-image + backgroundNo (uses background-color)Solid silhouette onlyExact token color without filter error

Why rasterizing SVGs for dark mode creates maintenance bloat

Shipping duplicate black and white PNGs doubles asset requests and blurs icons on 3x Retina displays.

Editing vector fill attributes directly or using Colr's CSS filter solver eliminates redundant dark-mode icon exports.

  • DOMParser SVG rewriting keeps crisp bezier geometry intact.
  • CSS filter chains start from brightness(0) saturate(100%) to guarantee deterministic tinting regardless of the source icon color.

Open Multi-Color SVG Recolor Lab

Exact CSS filter chain for tinting #000 icons to Brand Blue

Colr's CSS filter solver uses SPSA optimization in CIE perceptual space to minimize Delta-E between rendered pixels and your target Hex.

Exact CSS filter chain for tinting #000 icons to Brand Blue
CSS
.icon-brand {
  /* Turns black #000000 SVG into #2563EB (Delta-E < 0.8) */
  filter: brightness(0) saturate(100%) invert(27%) sepia(91%) saturate(2258%) hue-rotate(214deg) brightness(96%) contrast(94%);
}

Handling multi-color illustrations without breaking gradients

For multi-color brand illustrations, flat monochrome filters wash everything into one shade. Instead, detect every unique stop-color, fill, and stroke hex inside the SVG AST and remap each slot individually.

  • Inspect fill, stroke, and linearGradient stop-color entries automatically.
  • Swap brand accents while leaving neutral shadows untouched.

Solve exact CSS filter for any Hex

Tools featured in this guide

Related formats

Frequently asked questions

Why prepend brightness(0) saturate(100%) before CSS hue-rotate filters?

Starting with brightness(0) turns any arbitrary source SVG into pure black #000000 first so the downstream invert/sepia/hue-rotate math stays deterministic.

Can SVGs drop their file data on a server during Colr recoloring?

Never — DOMParser rewriting runs entirely inside your local browser tab.

More color guides