Skip to content

Instantly share code, notes, and snippets.

@gedankennebel
Forked from bergantine/gist:5243223
Created November 4, 2015 17:47
Show Gist options
  • Save gedankennebel/a4c9367cda02ad7e826f to your computer and use it in GitHub Desktop.
Save gedankennebel/a4c9367cda02ad7e826f to your computer and use it in GitHub Desktop.
CSS grayscale filter (go from grayscale to full color on hover) #css #sethneilson
img:hover {
-webkit-filter: grayscale(0%);
-webkit-transition: .5s ease-in-out;
-moz-filter: grayscale(0%);
-moz-transition: .5s ease-in-out;
-o-filter: grayscale(0%);
-o-transition: .5s ease-in-out;
filter: grayscale(0%);
}
img {
-webkit-filter: grayscale(100%);
-webkit-transition: .5s ease-in-out;
-moz-filter: grayscale(100%);
-moz-transition: .5s ease-in-out;
-o-filter: grayscale(100%);
-o-transition: .5s ease-in-out;
filter: grayscale(100%);
}
@msegers
Copy link

msegers commented Nov 30, 2015

so what browsers does this support, I still have this as well on some old css which works for older browsers:
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'/>#grayscale"); /* Firefox 10+, Firefox on Android /
filter: gray; /
IE6-9 */

@lamuertepeluda
Copy link

I made a Fiddle here https://jsfiddle.net/bvebgfo2/

@gideonmulder
Copy link

all transition rules on "img:hover" are not necessary, since they will override the rule that already exists in "img". Might save you some bytes;)

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