CSS - How to invert an image

You can invert an image (or any HTML element) using CSS filters.


In Summary

[the-hare.gif]
The hare takes aim

CSS

div.example {
    filter: invert(1);
}

Syntax invert(number | percent);

Note: CSS Filters are not supported by Internet Explorer.

Step by Step

Original Image
No filter
[the-hare.gif]
The hare takes aim

HTML

Simplified
<div class="example">
    <figure>
        <img src="images/the-hare.gif" />
        <figcaption>The hare takes aim</figcaption>
    </figure>
</div>

CSS

div.example {
}
invert
[the-hare.gif]
The hare takes aim

CSS

div.example {
    filter: invert(1);
}

Syntax invert(number | percent);



Ads by Google


Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath