Open In App

How to Add Shadow Effect on Hover to DIV Boxes in CSS ?

Adding a shadow effect on hover to DIV boxes is a popular technique to enhance the visual appeal and interactivity of a website. In this article, we will explore two different methods to achieve this effect using CSS.

Add Shadow Effect on Hover to DIV Box using box-shadow Property

The CSS box-shadow property is used to add shadow effects around an element’s frame. You can specify the horizontal and vertical offsets, blur radius, spread radius, and color of the shadow.




<!DOCTYPE html>
<html>
<head>
    <title>Shadow Effect on Hover</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: #4CAF50;
            transition: box-shadow 0.3s ease;
        }
  
        .box:hover {
            box-shadow: 10px 10px 20px rgba(36, 36, 36, 0.5);
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

Output



Explanation:

Add Shadow Effect on Hover to DIV Boxes using filter Property with drop-shadow

The filter property in CSS allows you to apply graphical effects like blurring or color shifting to an element. The drop-shadow function creates a shadow effect similar to box-shadow, but it can be applied to transparent images as well.




<!DOCTYPE html>
<html>
  
<head>
    <title>Shadow Effect on Hover with Filter</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: #4CAF50;
            transition: filter 0.3s ease;
        }
  
        .box:hover {
            filter: drop-shadow(10px 10px 20px rgba(36, 36, 36, 0.5));
        }
    </style>
</head>
  
<body>
    <div class="box"></div>
</body>
  
</html>

Output

Explanation:


Article Tags :