Loading Techie Utils…

Hex to CSS Filter

Find the CSS filter that turns a black icon into any hex colour. Free, and runs entirely in your browser — nothing you enter is uploaded or stored.

About CSS Filter Generator

Two tools in one. Build sets brightness, contrast, saturation, hue, blur, grayscale, sepia, invert and opacity by eye on a sample picture and writes the filter declaration. Recolour finds the filter chain that turns a black icon or image into any colour you choose.

Recolouring is the common reason people search for CSS filters: an icon arrives as a black PNG or an SVG in an <img>, and there is no fill to change. No formula maps a colour to filter values, so the tool searches for them — a stochastic optimisation that converges on the target — and reports how close it got. For nearly every colour the result is exact to the eye.

Order matters in a filter: functions apply left to right, so grayscale(1) sepia(1) and sepia(1) grayscale(1) give different pictures. Only the functions that differ from their neutral value are written out.

Where it helps

  • Finds the filter that recolours black to any colour, and says how accurate it is.
  • Builds filters by eye with a before-and-after preview.
  • Writes only the functions you changed, in a valid order.
  • Deterministic: the same target always gives the same filter.

Limits

  • Recolouring assumes a black source; for other colours, the CSS includes brightness(0) saturate(100%) first to make it black.
  • For inline SVGs, setting fill or using currentColor is simpler and exact; filters are for images you cannot edit.
  • Filters create a stacking context and can blur the whole element when combined with transforms.

Frequently asked questions

Why brightness(0) saturate(100%) at the start?

The recolour chain is calculated from black. Adding brightness(0) turns any icon into black first, so the chain works no matter what colour the icon started as.

Is there a better way to colour an icon?

Usually. An inline SVG can use fill or currentColor; an icon used as a CSS mask can take any background-color. A filter is the answer when you only have an <img> you cannot change.

Why is the result sometimes only 'very close'?

Some colours cannot be reached exactly by this filter chain from black. The search keeps the best result, and the difference is reported so you can judge it; it is rarely visible.

Related tools

More Colors & Design tools