Skip to content

Instantly share code, notes, and snippets.

@karlhorky
Created August 26, 2012 12:17
  • Star 89 You must be signed in to star a gist
  • Fork 25 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save karlhorky/3478370 to your computer and use it in GitHub Desktop.
Cross-Browser CSS Grayscale
img.grayscale.disabled {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0\'/></filter></svg>#grayscale");
-webkit-filter: grayscale(0%);
}
img.grayscale {
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"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
}
@andrienko
Copy link

Clearly does not work on IE11 by default.

@Fallenstedt
Copy link

To everyone saying it doesn't work on ie11. Duh. https://caniuse.com/#search=filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment