Open In App

How to change the color of an image to black and white using CSS ?

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

To change an image's color to black and white using CSS. This can be achieved by applying the filter property, which allows you to manipulate the visual effects of an image. We'll explore two different methods for converting an image to grayscale (black and white).

Methods to Convert an Image to Black and White Using CSS

There are two common ways to make an image appear in black and white using CSS:

  1. Using the grayscale() Method
  2. Using the brightness() and saturate() Methods

1. Using the grayscale() Method

The grayscale() Method converts the colors of an element to black and white. The level of grayscale is determined by the percentage specified:

  • 0% means the original colors of the image.
  • 100% means the image is completely grayscale (black and white).

Syntax:  

filter: grayscale(100%)

Example:  We will apply the grayscale() filter to an image to convert it to black and white.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>
        How to change the color of an images
        to black and white using CSS?
    </title>
    <style>
        .gfg {
            -webkit-filter: grayscale(100%);
            filter: grayscale(100%);
        }
    </style>
</head>
<body>
    <h2>GeeksForGeeks</h2>
    <h2>
        How to change the color of an images
        to black and white using CSS?
    </h2>
    <img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png">
    <br>
    <b>After Convert to Black and White</b> <br>
    <img class="gfg" 
         src=
 "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png">
</body>
</html>

Output:

2. Using brightness() and saturate() Methods

This method provides another way to achieve a black-and-white effect by adjusting the brightness and saturation of the image:

  • brightness() controls the brightness level of the image.
  • saturate() controls the saturation level (color intensity) of the image.

Setting the saturation to 0% effectively removes all colors, while adjusting brightness can fine-tune the intensity of black and white.

Syntax:

filter: brightness(0.5) saturate(0%);

Example: We will use both brightness() and saturate() to convert the image to black and white.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>
        How to change the color of an images
        to black and white using CSS?
    </title>
    <style>
        .gfg {
            filter: brightness(0.5) saturate(0%);
        }
    </style>
</head>
<body>
    <h2>GeeksForGeeks</h2>
    <h2>
        How to change the color of an images
        to black and white using CSS?
    </h2>
    <img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png">
    <br>
    <b>After Convert to Black and White</b> <br>
    <img class="gfg" 
         src=
 "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png">
</body>
</html>

Output:


Similar Reads