How to darken an Image using CSS ?

Method 1: Using the filter property: The filter property is used to apply various graphical effects to an element. The brightness() function can be used as a value to apply a linear multiplier to make it appear darker or lighter than the original. To make an image darker, any value below 100% could be used to darken the image by that percentage.

Syntax:

filter: brightness(50%)

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to Darken an Image
        using CSS?
    </title>
  
    <style>
        .darkened-image {
            filter: brightness(50%);
      
            background-image: url(
            height: 94px;
            width: 120px;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
      
    <b>
        How to Darken an Image
        with CSS?
    </b>
      
    <p>
        The image below is the
        normal image:
    </p>
      
    <img src=
      
    <p>
        The image below is the
        darkened image:
    </p>
      
    <div class="darkened-image"></div>
</body>
  
</html>

chevron_right


Output:
using-filter

Method 2: Using the background-image property with a linear gradient: The background-image property in CSS supports the use of multiple backgrounds that are layered on top of each other. Using the linear-gradient property, a black colored background is used as the front layer and the image to be darkened is used as the back layer. The order of the background-image property specifies the front layer to be specified first before defining the layers at the back.
The opacity of the black gradient can be changed to control the amount of darkening. This can be used accordingly to darken the image as required.



Syntax:

background-image: linear-gradient(rgba(0, 0, 0, 0.5),
                       rgba(0, 0, 0, 0.5)), url("url_of_image"))

Example: Using an opacity of 0.5 of the background gradient to darken the image.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to Darken an Image with CSS?
    </title>
      
    <style>
        .darkened-image {
            background-image: 
            linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
            url(
            height: 94px;
            width: 120px;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
      
    <b>
        How to Darken an Image
        with CSS?
    </b>
      
    <p>
        The image below is the
        normal image:
    </p>
      
    <img src=
      
    <p>
        The image below is the
        darkened image:
    </p>
      
    <div class="darkened-image"></div>
</body>
  
</html>

chevron_right


Output:
using-multiple-bg




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.