Related Articles

Related Articles

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:



Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Supported browsers:

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

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :