CSS Portal

invert() CSS Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
invert()
CSS FunctionThis function is supported by all modern browsers.
Updated 31st December 2025

Description

The invert() CSS function is used to invert the colors of an element, producing a negative of its original colors. It works by inverting the brightness of each pixel: black becomes white, white becomes black, and other colors are flipped to their complementary colors. This can be particularly useful for creating visual effects such as dark mode adjustments, highlighting elements, or emphasizing images without modifying the source content.

When invert() is applied, it is typically used with the filter property, allowing you to combine it with other functions like grayscale() or blur() for more complex visual effects. The function accepts a value between 0 and 1, where 0 leaves the element unchanged, and 1 fully inverts the colors. Values between 0 and 1 produce partial inversion, allowing for subtle adjustments.

For example, applying invert(1) to an img element will turn a photograph into a photographic negative:

img {
  filter: invert(1);
}

You can also combine it with other filters for creative effects:

img {
  filter: invert(0.7) grayscale(0.5);
}

This will partially invert the colors while adding a muted grayscale effect, giving a stylized look without changing the original img source.

Because invert() affects the visual rendering, it does not alter the underlying img file or the document structure, making it safe for temporary visual adjustments or dynamic themes.

Syntax

invert() = invert( <number-percentage>? )

Values

  • number-percentageA value of 0 leaves the image original. A value of 100% or 1 completely inverts the colors of the picture. Values ​​from 0% to 100% or from 0 to 1 invert colors partially.

Example

<div class="container">
<div class="box normal">
<p>Original Colors</p>
</div>

<div class="box inverted">
<p>Inverted Colors</p>
</div>
</div>
/* Container for layout */
.container {
display: flex;
gap: 20px;
font-family: sans-serif;
}

/* Base styles for both boxes */
.box {
width: 200px;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
background-color: #3498db; /* A nice blue */
color: white;
border: 2px solid #2980b9;
}

/* The Inversion Function */
.inverted {
/* 100% flips the colors entirely */
filter: invert(100%);
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS invert() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee