This CSS code works pretty nice for Internet Explorer until 9.
img.gray {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
filter: gray;
-webkit-filter: grayscale(1);
}
But what do I need to do for Internet Explorer 10 ?
IE10 does not support DX filters as IE9 and earlier have done, nor does it support a prefixed version of the greyscale filter.
However, you can use an SVG overlay in IE10 to accomplish the greyscaling. Example:
(from: http://www.karlhorky.com/2012/06/cross-browser-image-grayscale-with-css.html)
Simplified JSFiddle: http://jsfiddle.net/KatieK/qhU7d/2/
More about the IE10 SVG filter effects: http://blogs.msdn.com/b/ie/archive/2011/10/14/svg-filter-effects-in-ie10.aspx
Inline SVG can be used in IE 10 and 11 and Edge 12.
I've created a project called gray which includes a polyfill for these browsers. The polyfill switches out
<img>
tags with inline SVG: https://github.com/karlhorky/grayTo implement, the short version is to download the jQuery plugin at the GitHub link above and add after jQuery at the end of your body:
Then every image with the class
grayscale
will appear as gray.You can see a demo too if you like.
Use this jQuery plugin https://gianlucaguarini.github.io/jQuery.BlackAndWhite/
That seems to be the only one cross-browser solution. Plus it has a nice fade in and fade out effect.