How to change color of PNG image using CSS?

Given an image and the task is to change the image color using CSS. Use filter function to change the png image color. Filter property is mainly used to set the visual effect to the image. There are many property value exist to the filter function.

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

Example 1: This example use grayscale filter to change the colored image into grayscale image.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!-- HTML code to change the png image color 
        using filter property -->
<!DOCTYPE html> 
<html
    <head
        <title>Convert into grayscale image</title
        <style
            img { 
                filter: grayscale(10); 
            
        </style
    </head
      
    <body
        <h2>Grayscale Image</h2
        <img src
        width="500px" height="250px" alt="filter applied" /> 
    </body
</html

chevron_right


Output:
Original Image:

After applying filter:



Example 2: This example use many filter to the image.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!-- HTML code to change the png image color 
        using filter property -->
<!DOCTYPE html> 
<html
    <head
        <title>Convert image into different color</title
        <style
            img { 
                width:40%;
                float:left;
            }
            .image1 {
                filter: invert(100%);
            }
            .image2 {
                filter: sepia(100%);   
            }
        </style
    </head
      
    <body
        <img class = "image1" src
        width="500px" height="250px" alt="filter applied" /> 
          
        <img class = "image2" src
        width="500px" height="250px" alt="filter applied" /> 
    </body
</html

chevron_right


Output:



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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.