Hex Colour to CSS Filter (Recolour a Black Icon)
Searches for a CSS filter chain that turns a black image or icon into your target colour and reports how close the result is.
Use the tool
Why this tool exists
You cannot set the fill of an img or a CSS background icon with a colour value, but you can change its pixels with filter. Starting from black, a chain of invert, sepia, saturate, hue-rotate, brightness and contrast can reach most colours.
The tool uses the colour matrices from the CSS Filter Effects spec and a fixed-seed search, so the same colour always gives the same answer. It shows the colour the chain really produces and the largest channel error, so you see when a match is only rough. I checked five colours against Chrome canvas filters and they were within 3 of 255 per channel.
How to use it
- Enter a hex colour such as #1d4ed8.
- Read the filter line and the colour it actually produces.
- Apply the filter to a black image or icon.
- Copy it into your CSS.
Frequently asked questions
Does it work on non-black images?
No. The chain is solved starting from pure black. For other colours, use an SVG with currentColor instead.
Why is the match not exact?
The search is approximate and values are rounded to whole numbers. The error is shown so you can judge.
Will it look the same in every browser?
Filters are specified, but small rendering differences exist. Check on your target browsers.