Convert an image into grayscale image using HTML/CSS
Given a colored image and the task is to convert the image into grayscale image using CSS property. In CSS, filter property is used to convert an image into grayscale image. Filter property is mainly used to set the visual effect of an image.
Syntax:
filter: grayscale()
Example 1: In this example, use filter: grayscale(100%) to convert an image into grayscale.
<!DOCTYPE html> <html> <head> <title>Convert into grayscale image</title> <style> img { -webkit-filter: grayscale(100%); filter: grayscale(100%); } h1 { color:green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2>Grayscale Image</h2> <img src= width="500px" height="250px" alt="filter applied" /> </center> </body> </html> |
chevron_right
filter_none
Output:

Example 2:
<!DOCTYPE html> <html> <head> <title>Convert into grayscale image</title> <style> img { -webkit-filter: grayscale(1); filter: grayscale(1); } img:hover { -webkit-filter: grayscale(0); filter: none; } h1 { color:green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2>Grayscale Image</h2> <img src= width="500px" height="250px" alt="filter applied" /> </center> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- Convert an image into Blur using HTML/CSS
- How to convert a PDF document to a preview image in PHP?
- How to convert an image to base64 encoding in PHP?
- How to convert an HTML element or document into image ?
- Saving an Image from URL in PHP
- CSS | Image Gallery
- CSS | Image Sprites
- HTML | Mapping Image
- How to get the width and height of an image ?
- Drop shadow for PNG image using CSS
- Set the size of background image using CSS ?
- How to change color of PNG image using CSS?
- jQuery | :image Selector
- CSS | border-image Property
- CSS | background-image Property
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.



