Skip to content
Jellykit

CSS Filter From Color

Find a CSS filter chain that turns a black icon or SVG into any target color, with a score for how close it gets.

  • Runs on your device
  • Works in the background
Loading tool

About CSS Filter From Color

When an icon arrives as an image you cannot restyle, such as an SVG in an img tag or a PNG, CSS filters are the only way to change its color. Pick the color you want and this tool searches for a chain of invert, sepia, saturate, hue-rotate, brightness and contrast that turns black into it.

It shows the predicted result beside your target, a black square with the filter applied as your browser draws it, and an accuracy score, so you can see how good the match is before using it. Another attempt number starts the search afresh when you want a different chain.

How it works

  1. Each filter function is a fixed formula from the Filter Effects specification: a color matrix or a straight-line change to each channel, clamped after every step. The tool runs the same formulas on a black pixel.
  2. A downhill simplex search tunes the six amounts to bring the result as close to the target as possible, starting from several repeatable random points and keeping the best.
  3. Closeness is the distance between the two colors in OKLab, a space built so that equal distances look equally different. Accuracy is 100 minus that distance times 100.
  4. The amounts are rounded to the precision written in the CSS, and the score is for the rounded chain, so it is what you will get.

Questions

Why does my icon come out the wrong color?

The chain is worked out for black pixels. If the icon is another color, turn on Icon is not black, which adds brightness(0) at the start to make every pixel black first.

How accurate is it?

For nearly every color the predicted difference is well under 1, which nobody can see. Browsers may round intermediate results slightly differently, so check the black square beside the target in your own browser.

Should I use this instead of changing the SVG fill?

Only when you cannot change the fill. An inline SVG with fill="currentColor", or a CSS mask, gives exact colors and is easier to maintain. Filters are for images you cannot edit.

Does it keep transparency and antialiasing?

Yes. Filters change color only, so transparent areas stay transparent and soft edges stay soft. Grays inside the icon, however, become other colors, so it suits single-color icons best.

Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.