CSS Function

invert()

The invert() filter function inverts the colors of an element's rendering, producing a photographic negative effect.

Syntax

filter: invert(amount)

Parameters

NameTypeRequiredDescription
amountnumber | percentageYesInversion amount: 0 (original), 0.5/50% (mid-gray), 1/100% (fully inverted)

Examples

Full inversion

Produces a photographic negative.

css
img {
  filter: invert(1);
}

Dark mode icon hack

Quick dark mode for black icons: invert then restore hue.

css
.dark img.icon {
  filter: invert(1) hue-rotate(180deg);
}

Tailwind utility

Tailwind's invert utility with dark mode variant.

html
<img class="dark:invert" src="logo-dark.svg" />

Browser Support

Chrome

v18++

Firefox

v35++

Safari

v6++

Edge

v12++

Opera

v15++

Tailwind Equivalent

You can achieve similar results in Tailwind CSS using the following utility classes:

invert / invert-0: toggles between full and no inversion

Frequently Asked Questions

How does invert work mathematically?
Each color channel value x is replaced with (1 - x). So white (1,1,1) becomes black (0,0,0) and vice versa.
Why combine invert with hue-rotate for dark mode?
invert(1) reverses all colors including hue. Adding hue-rotate(180deg) restores the original hue while keeping the inverted lightness, preserving the color intent.

Explore CSS Color Tools

Try our free tools to work with invert() and other CSS color functions.

Open Tools