Display Images as Grayscale with CSS Filters

By  on  

CSS filters aren't yet widely supported but they are indeed impressive and a modern need for web imagery.  CSS filters allow you to modify the display of images in a variety of ways, one of those ways being displaying images as grayscale.

Doing so requires the most minimal of CSS:

img.bw {
	filter: grayscale(1);
}

You can even animate an image to or from grayscale:

img.bw {
	filter: grayscale(0);
}

img.bw.grey {
	filter: grayscale(1);
	transition-property: filter;
	transition-duration: 1s;	
}

CSS filters allow much more than just grayscale adjustments, so if you haven't taken the time, please play around with my CSS filter sandbox.  Remember that if the user chooses to download the image, it is downloaded in its original colored displays, but for online display purposes, CSS filters do the trick!

Recent Features

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

Incredible Demos

  • By
    Fx.Rotate:  Animated Element Rotation with MooTools

    I was recently perusing the MooTools Forge and I saw a neat little plugin that allows for static element rotation: Fx.Rotate. Fx.Rotate is an extension of MooTools' native Fx class and rotates the element via CSS within each A-grade browser it...

  • By
    MooTools Wall Plugin

    One of the more impressive MooTools plugins to hit the Forge recently was The Wall by Marco Dell'Anna.  The Wall creates an endless grid of elements which can be grabbed and dragged, fading in elements as they are encountered.  Let me show...

Discussion

  1. MaxArt

    I knew about CSS filters, but what always restrained me to use them is that they’re limited to Webkit/Blink browsers. Firefox supports just the url syntax.
    Many designers love them and for a reason. I just wish they were more widely supported.

  2. I cant find the difference between the 3 images. All images seems to be the same color! Is this a browser problem (firefox) or i don’t see it?

    • Yes, it doesn’t display the CSS filters effect in Firefox and also Opera… Hopefully it will be cross-browser in the future.

  3. I haven’t used css filters so far and this article fits perfectly for a design I want to implement.
    Thanks so much, great stuff

  4. Brian Douglas

    Is there a Firefox workaround for this?

  5. Grayscale is even better appreciated when used in action. It works perfectly on latest version of Chrome and firefox as seen on http://www.myweeblytricks.com/2014/09/weebly-tricks-72-grayscale-image.html

  6. David

    Unfortunately it does not work in IE11.

  7. LOC

    Check this, it worked for me perfectly: https://chrome.google.com/webstore/detail/grayscale-black-white-col/cjimlckjgclgboeebpjlipmokolejppk?hl=en (Chrome only) Using this app I can convert any web page to black & white color scheme.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!