Skip to content
Related Articles

Related Articles

Improve Article
How to add filter to the background image using CSS ?
  • Last Updated : 15 Oct, 2020

The purpose of this article is to learn how to add filters to an image using CSS. The CSS filter property is used to set the visual effect of an element. This property is mostly used in image content.

Syntax:

filter: none | blur() | brightness() | contrast() | drop-shadow() | grayscale() | hue-rotate() | invert() | opacity() | saturate() | sepia() | url();

Example:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        body {
            background-image: url(
            filter: brightness(90%);
            filter: grayscale(70%);
        }
    </style>
</head>
  
<body>
    <center>
        <h2>
            GeeksForGeeks
        </h2>
        <h2>
            How to add a filter to a 
            background image using CSS?
        </h2>
    </center>
</body>
  
</html>    

Output:



Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        .darkened-image {
            filter: brightness(50%);
            background-image: url(
            height: 94px;
            width: 120px;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
    <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>                    

Output:

Supported browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari



My Personal Notes arrow_drop_up
Recommended Articles
Page :