Convert an Image Into Gray Scale Image Using Html and Css

admin_img Posted By Bajarangi soft , Posted On 08-10-2020

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.

Gray Scale Image

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:red;
        }
    </style>
</head>
<body>
<center>
    <h1>Bajarangi soft</h1>
    <h2>Grayscale Image</h2>
    <img src="logo.jpg" width="500px" height="250px" alt="filter applied" />
</center>
</body>
</html>
Example 2:
In this Example If You Place Over The Image will get Image without gray scale
<!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>Bajarangi Soft</h1>
    <h2>Grayscale Image</h2>
    <img src=
                 "logo.jpg"
         width="500px" height="250px" alt="filter applied" />
</center>
</body>
</html>

Related Post