The Wayback Machine - https://web.archive.org/web/20211205114509/https://dev.to/0shuvo0/box-shadow-vs-drop-shadow-in-css-1cno

DEV Community

Cover image for Box shadow vs. drop shadow in CSS
Shuvo
Shuvo

Posted on

Box shadow vs. drop shadow in CSS

We all know that we can use box-shadow to add shadows to our HTML elements. eg

.box{
    box-shadow: 2px 3px 10px rgba(0, 0, 0, .5);
}
Enter fullscreen mode Exit fullscreen mode

CSS box shadow

But did you know that we can achieve the same using drop-shadow filter. You simply have to pass the shadow value in the drop-shadow function

.box{
    filter: drop-shadow(2px 3px 10px rgba(0, 0, 0, .5));
}
Enter fullscreen mode Exit fullscreen mode

CSS drop shadow filter

Although in this example both box-shadow and drop-shadow does the same thing. But if we were to add box-shadow on a PNG image you will see the shape of box-shadow is rectangular/box.

img{
  box-shadow: 2px 3px 10px rgba(0, 0, 0, .5);
}
Enter fullscreen mode Exit fullscreen mode

CSS box shadow on png image
While if we add drop-shadow to a PNG, the shape of the shadow will be same as the shape of the visible area of the PNG.

img{
    filter: drop-shadow(2px 3px 10px rgba(0, 0, 0, .5));
}
Enter fullscreen mode Exit fullscreen mode

CSS drop shadow filter on png image

Make sure you checkout my other articles and YouTube channel

0shuvo0 image




Was it helpful? Support me on Patreon

Patreon Logo

Discussion (6)

Collapse
andrewbaisden profile image
Andrew Baisden

Nicely explained.

Collapse
0shuvo0 profile image
Shuvo Author

Many many Thanks 💖

Collapse
baenencalin profile image
Calin Baenen

If I recall correctly, being rectangle/conforming to visible shape also applies to text, and other things with possible transparency, doesn't it?

Collapse
0shuvo0 profile image
Shuvo Author

Yes
You cab use text-shadow instead of box-shadow for texts btw

Collapse
boyney profile image
Boyne

I didn’t even know drop shadows existed until now

Collapse
0shuvo0 profile image
Shuvo Author

Hope you have a lot of fun with it