Open In App

Understanding CSS Shadows: Box Shadow vs. Drop Shadow

In this article, we explore the complex world of CSS shadows and clarify the key distinctions between “Box Shadow” and “Drop Shadow.”

What is Box Shadow?

Syntax:

box-shadow: h-offset v-offset blur spread color;

Advantages of Using Box Shadow:

Example of Box Shadow: This example illustrates the use of the box-shadow property where properties such as h-offset, v-offset, blur, spread & color are applied along with their values.






<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,
                   initial-scale=1.0">
    <title>Box-Shadow Example</title>
    <link rel="stylesheet" href="./style.css">
</head>
 
<body>
    <div class="box">
        <h4>Geeksforgeeks</h4>
    </div>
    <div class="box-2">
        <h4>Geeksforgeeks</h4>
    </div>
    <div class="box-3">
        <h4>Geeksforgeeks</h4>
    </div>
    <div class="box-4">
        <h4>Geeksforgeeks</h4>
    </div>
</body>
 
</html>




* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
 
body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    gap: 30px;
    margin: 0;
}
 
.box {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    box-shadow: 10px 10px 2px 1px rgb(11, 150, 9);
    align-items: center;
}
 
.box-2 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    box-shadow: 10px -10px rgb(11, 150, 9);
    align-items: center;
}
 
.box-3 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    box-shadow: inset 5em 1em rgb(11, 150, 9);
    align-items: center;
}
 
.box-4 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    box-shadow: 3px 3px rgb(11, 150, 9), -1em 0 .4em rgb(184, 77, 38);
    align-items: center;
}

Output:

box-shadow

What is Drop Shadow?:

Syntax:

drop-shadow(<shadow>)

Advantages of Using Drop Shadow:

Example of Drop-Shadow: This example illustrates the use of the drop-shadow property where properties such as h-offset, v-offset, blur, & color are applied along with their values.




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,
                   initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./style.css">
</head>
 
<body>
    <div class="box-2">
        <h4>Geeksforgeeks</h4>
    </div>
    <div class="box-3">
        <h4>Geeksforgeeks</h4>
    </div>
    <div class="box-4">
        <h4>Geeksforgeeks</h4>
    </div>
</body>
 
</html>




* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
 
body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    gap: 30px;
    margin: 0;
}
 
.box-2 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    filter: drop-shadow(0 0 0.75rem rgb(11, 150, 9));
    align-items: center;
}
 
.box-3 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    filter: drop-shadow(20px 10px 4px rgb(11, 150, 9));
    align-items: center;
}
 
.box-4 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
    background-color: rgb(230, 242, 246);
    border-radius: 10px;
    filter: drop-shadow(0 -6mm 4mm rgb(11, 150, 9));
    align-items: center;
}

Output:

drop-shadow

Difference between Box Shadow and Drop Shadow

Property

box-shadow

drop-shadow

Definition

CSS property that creates a rectangular shadow around an element.

CSS filter function that creates a shadow that conforms to the shape (alpha channel) of an element.

Shadow

Can have multiple shadows defined with commas

Only a single shadow is used

Performance

Faster

Slower

Example:

Creating a rectangular shadow around an element, adding depth and dimension to a design, making an element stand out from the page.

Creating a shadow that conforms to the shape of an element, creating realistic shadows, improving accessibility.


Article Tags :