The Wayback Machine - https://web.archive.org/web/20240624063052/https://www.geeksforgeeks.org/convert-an-image-into-grayscale-image-using-html-css/
Open In App

Convert an image into grayscale image using HTML/CSS

Last Updated : 30 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to convert an image into a grayscale image using CSS properties. CSS provides a filter property that can be used to apply visual effects to an image. In our case, we can use this property to convert an image into a grayscale image.

The grayscale() filter in CSS can take values between 0 and 1. Here’s what these values represent:

Value

Description

0

Represents no grayscale effect, meaning the image remains in full color.

1 or 100%

Represents full grayscale, making the image completely black and white.

Syntax:

filter: grayscale()

Example 1: In this example, use filter: grayscale(100%) to convert an image into grayscale.

html




<!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>
    <h1>GeeksforGeeks</h1>
    <h2>Grayscale Image</h2>
    <img src=
         width="500px"
         height="250px" alt="filter applied" />
</body>
 
</html>


Output:

grayscale image

Example 2: In this example, use filter: grayscale(1) to convert an image into grayscale.

html




<!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>


Output:

grayscale image



Previous Article
Next Article

Similar Reads

How to apply colored shadow and border properties to a grayscale image?
There is a very simple method of applying the grayscale effect to an image. Using the filter() property, we can apply grayscale effect to any HTML element. When we apply a colored box-shadow to an image having a grayscale property, the shadow turns grayscale too. For example: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt;
3 min read
How to Create a GrayScale Effect using CSS ?
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 tra
2 min read
Tailwind CSS Grayscale
The Grayscale class is used to apply a filter to the image to set the grayscale of the image. In CSS, we do that by using the CSS grayscale() Function. Tailwind CSS newly added feature brightness in 2.1 version. Grayscale: grayscale-0: This class is used to represents the original image.grayscale: This class is used to represents the linear multipl
1 min read
CSS grayscale() Function
The grayscale() function in CSS is an inbuilt function that is used to apply a filter to the image to set the grayscale of the image. Syntax: grayscale( amount )Parameters: This function accepts a single parameter amount that holds the value of grayscale. The value of grayscale is set in terms of number and percentage. The value 0% represents the o
1 min read
Tailwind CSS Backdrop Grayscale
The Backdrop Grayscale class is used to apply a filter to the image to set the grayscale of the image. Tailwind CSS newly added feature brightness in 2.1 version. Backdrop Grayscale: backdrop-grayscale-0: This class is used to represents the original element.backdrop-grayscale: This class is used to represents the linear multipliers on the effect o
1 min read
jQWidgets jqxChart grayScale Property
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful and optimized framework, platform-independent, and widely supported. jqxChart is a lightweight and powerful chart widget written 100% in javascript. It offers many advanced features and supports three different rendering technologi
2 min read
Primer CSS Grayscale
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by object-oriented CSS principles, functional CSS, an
2 min read
Less.js Color Operation grayscale() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS uses a dynamic style sheet language, it is superior. LESS is adaptable enough to function in a variety of browsers. Web browsers can only use CSS if it is built and developed using a computer language ca
3 min read
Node Jimp | Color grayscale
Introduction The grayscale modifier is an inbuilt color modifier in Nodejs | Jimp which desaturate an image color into grayscale depending on a given amount, from 0 to 100. Syntax: image.color([ { apply: 'grayscale', params: [value] }]);Parameter: value - This parameter stores the amount of grayscale to apply. It takes values from 0 - 100.Input Ima
1 min read
Convert an image into Blur using HTML/CSS
Given an image and the task is to convert the image into blur image using CSS property. In CSS, filter property is used to convert an image into blur image. Filter property is mainly used to set the visual effect of an image. Syntax: filter: blur() Example 1: This example use blur filter to convert the image into blur image. Original Image: &lt;!DO
1 min read
three90RightbarBannerImg