An effect like this can be achieved using webkit filters:
img { -webkit-filter: grayscale(100%); -webkit-filter: contrast(0%); -webkit-filter: brightness(0%); } img:hover { -webkit-filter: grayscale(0%); -webkit-filter: contrast(100%); -webkit-filter: brightness(100%); }
and jsfiddle to demonstrate: http://jsfiddle.net/7Ljcgj79/
Please note that this method will not be supported in all browsers . To support IE, you can set this as background-image and change it on hover.
Using two images for better browser compatibility
If you want to use two images, you can achieve the same effect with much broader browser support by simply replacing the image with a hover . Something like that:
div { height: 400px; width: 400px; background-image: url('http://i.stack.imgur.com/Pmz7l.png'); background-repeat: no-repeat; } div:hover { background-image: url('http://i.stack.imgur.com/gZw5u.png'); }
And the updated fiddle: http://jsfiddle.net/7Ljcgj79/2/
Improved example supporting all colors
I did not visit this post after a while, and I definitely see that it could be improved (all I had to do was set the brightness to 0%, nothing else was needed and actually had no effect). I wanted to give an updated answer, though, in response to the comment. This solution requires a bit more work, but supports all colors, not just black! Here are the important bits:
HTML
<svg> <filter id="monochrome" color-interpolation-filters="sRGB"> <feColorMatrix type="matrix" values="0 0 0 0 0.6588 0 0 0 0 0.4745 0 0 0 0 0.1686 0 0 0 1 0" /> </filter> </svg>
CSS
img { -webkit-filter: url(#monochrome); filter: url(#monochrome); } img:hover { filter: none; }
And updated fiddle: http://jsfiddle.net/7Ljcgj79/16/
This method uses <fecolormatrix> , basically an advanced function, to define your own filters. What I did here is turn all the color channels to zero (all zeros for the first four columns) and then add to them the constant value that I need (this is the last column). Make sure that the <filter> has type="matrix" , and the <fecolormatrix> color-interpolation-filters="sRGB" , or it will interpret your matrix differently.
These posts were very helpful if you want to know more: https://alistapart.com/article/finessing-fecolormatrix and https://css-tricks.com/color-filters-can-turn-your-gray-skies- blue /