The Wayback Machine - https://web.archive.org/web/20240118174022/https://www.geeksforgeeks.org/drop-shadow-for-png-image-using-css/
Open In App
Related Articles

Drop shadow for PNG image using CSS

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

There is a basic way to add shadow effect on images but that effect will behave like the image is square, so there is another way to do the shadow which is basically applied on PNG images. The normal shadow effect will always put a square image shadow for the image which can be squared or cannot be squared but the shadow will be always square. filter:drop-shadow(); and text-shadow(); property is more eye pleasant compare to box-shadow:() property.

Syntax:

filter: drop-shadow();

Example 1: This example uses filter: drop-shadow() property to add shadow effect on pngimage.




<!DOCTYPE html>
<html>
  
<head>
      
    <!-- CSS style to add shadow -->
    <style>
        img {
            filter: drop-shadow(5px 5px 5px #222);
            width:200px;
            height:220px;
        }
    </style>
</head>
  
<body style="text-align:center;">
    <h3>Drop shadow effect on png</h3>
    <img src=
</body>
  
</html>                                  


Output:

Example 2: This example differentiate between filter:drop-shadow();, text-shadow(); and box-shadow:(); property.




<!DOCTYPE html> 
<html> 
      
<head> 
    <style> 
        img {
            width:120px;
        }
        .Box-shadow {
            float:left;
            box-shadow:2px 2px 2px gray;
        }
          
        .Text-shadow {
            float:right;
            text-shadow:2px 2px 2px gray;
        }
        .Drop-shadow {
            float:right;
        }
        .Drop-shadow img {
            filter:drop-shadow(2px 2px 2px gray);
        }
    </style> 
</head> 
  
<body> 
  
    <div class = "images"> 
        <div class="Box-shadow">
            <p>Box-shadow
                <img src=
            </p>
        </div>
          
        <div class="Text-shadow">
            <p>Text-shadow
                <img src=
            </p>
        </div>
          
        <div class="Drop-shadow">
            <p>Drop-shadow
                <img src=
            </p> 
        </div>
    </div> 
</body> 
  
</html>                                                    


Output:


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Apr, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials