Open In App

How to Add Shadow to Image in CSS ?

Adding shadow to an image can enhance its visual appeal and make it stand out on your webpage. In this article, we will explore various approaches to add shadow to an image using CSS.

Add Shadow on Image using box-shadow Property

The box-shadow property is commonly used to add shadow effects to elements in CSS. It allows you to specify the horizontal and vertical offsets, blur radius, spread radius, and color of the shadow.




<!DOCTYPE html>
<html>
  
<head>
    <title>Image Shadow with box-shadow</title>
    <style>
        .image {
            box-shadow: 8px 8px 15px rgba(0, 0, 0, 0.5);
        }
    </style>
</head>
  
<body>
    <img class="image" src=
        alt="Image with Shadow">
</body>
  
</html>

Output



Explanation:

Add Shadow on Image on Hover

You can also add a shadow effect to an image when it is hovered over, creating an interactive visual effect.




<!DOCTYPE html>
<html>
  
<head>
    <title>Image Shadow on Hover</title>
    <style>
        .image {
            transition: box-shadow 0.3s ease;
        }
  
        .image:hover {
            box-shadow: 6px 6px 12px rgba(0, 0, 0, 0.6);
        }
    </style>
</head>
  
<body>
    <img class="image" src=
        alt="Hover to see Shadow">
</body>
  
</html>

Output

Explanation:

Add Shadow on Image using filter Property with drop-shadow

The filter property with the drop-shadow function can also be used to add a shadow effect. This approach is particularly useful when you want to apply the shadow to transparent images or SVGs.




<!DOCTYPE html>
<html>
  
<head>
    <title>Image Shadow with filter</title>
    <style>
        .image {
            filter: drop-shadow(8px 8px 16px rgba(0, 0, 0, 0.5));
        }
    </style>
</head>
  
<body>
    <img class="image" src=
        alt="Image Shadow">
</body>
  
</html>

Output

Explanation:


Article Tags :