The Grayscale is an effect that provides transition effect from colored image to monochrome image or vice-versa. This effect can be applied to various events like mouse-hover or you can also use a button to activate the effect.
Approach: We will be using the CSS built in function grayscale() to create this effect.
Example 1: First let’s look at transition of colored image to monochrome image. For this we will use grayscale() function in the hover selector. We just set grayscale value to 100% on mouse hover.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title>Gray Scale Effect</title> <style> body{ background: grey; } img{ position: absolute; top:40%; left:50%; transition:.5s ease-in-out; } img:hover{ filter:grayscale(100%); } </style> </head> <body> <img src= </body> </html> |
Output:

Example 2: Now for a transition from monochrome to the colored image, we will do the reverse process of example 1. We will use the grayscale() function at 100% for the <img> tag and then reduce it to 0% on mouse-hover.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title>Gray Scale Effect</title> <style> body{ background: grey; } img{ position: absolute; top:40%; left:50%; filter:grayscale(100%); transition:.5s ease-in-out; } img:hover{ filter:grayscale(0%); } </style> </head> <body> <img src= </body> </html> |
Output:

Recommended Posts:
- Convert an image into grayscale image using HTML/CSS
- CSS | grayscale() Function
- How to create Glowing Star effect using HTML and CSS?
- How to create fade-in effect on page load using CSS ?
- How to Create Paradoxical Effect using CSS ?
- How to Create Liquid Filing Effect on Text using HTML and CSS ?
- How to create shock wave or explosion effect using HTML and CSS ?
- How to Create Skeleton Screen Loading Effect using CSS ?
- How to Create Loading Blur Text Animation Effect using HTML and CSS ?
- How to create Skewed Background with hover effect using HTML and CSS?
- How to create paper corner fold effect on hover by using HTML and CSS?
- Create a 3D Text Effect using HTML and CSS
- How to Create an Effect to Change Button Color using HTML and CSS ?
- How to create a bouncing bubble effect using CSS ?
- How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ?
- How to Create Embossed Text Effect using CSS ?
- How to create followspot effect using HTML CSS and jQuery ?
- How to Create Floating Box Effect using HTML and CSS ?
- How to create text-reveal effect using HTML and CSS ?
- How To Create Carved Text Effect using CSS?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


