π What Is drop-shadow()?
The drop-shadow() function is part of the CSS filter system. It applies a shadow to an element based on its alpha (transparent) shape β unlikebox-shadow, which always uses a rectangular box.
This is especially useful for images, icons, SVGs, and irregular shapes. π¨β¨
π§© Basic Syntax
Syntax
filter: drop-shadow(<offset-x> <offset-y> <blur-radius> <color>);β All values work similarly to box-shadow but apply to the non-transparent region of an element.
π― drop-shadow() vs box-shadow
| Property | Follows Shape? | Best Use |
|---|---|---|
| drop-shadow() | β Yes (transparent areas ignored) | Images, icons, PNGs, SVGs |
| box-shadow | β Always a rectangle | Buttons, cards, containers |
Note
π§ͺ Basic Example
Simple drop-shadow
img {
filter: drop-shadow(5px 5px 10px rgba(0,0,0,0.4));
}β This adds a soft shadow behind an image, following its edges.
π¨ Layered drop-shadows
Just like filters, you can stack multiple drop shadows.
Multiple shadows
.icon {
filter: drop-shadow(2px 2px 3px rgba(0,0,0,0.3))
drop-shadow(4px 4px 8px rgba(0,0,0,0.2));
}β Produces a deeper, more realistic shadow.
π§ Perfect for SVG Icons
SVG shadow
svg {
filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}β The shadow follows the actual vector path, not a box.
π Colored Shadows
Colored shadow
.sticker {
filter: drop-shadow(0 0 6px #00eaff);
}β Great for neon, glowing effects, or gaming UI graphics.
π₯ Advanced: Glow Effect with drop-shadow()
Glow effect
.glow {
filter: drop-shadow(0 0 6px #7f5af0)
drop-shadow(0 0 12px #7f5af0)
drop-shadow(0 0 20px #7f5af0);
}β Stacking shadows creates a smooth glowing aura.
π§ͺ Example: Floating Image Effect
Floating shadow
.float {
filter: drop-shadow(0 20px 20px rgba(0,0,0,0.25));
}β Makes the element look like itβs lifted off the page.
π¬ Animation with drop-shadow()
Animated shadow
@keyframes pulseShadow {
0% { filter: drop-shadow(0 0 5px #ff00aa); }
100% { filter: drop-shadow(0 0 15px #ff00aa); }
}
.logo {
animation: pulseShadow 1s ease-in-out infinite alternate;
}β Perfect for animated glow or attention-grabbing effects.
β οΈ Important Notes
- drop-shadow() is part of filter, so it may affect performance on large elements.
- Use box-shadow for layout components.
- Use drop-shadow() for icons, PNGs, SVG logos, stickers, etc.
- Works well with PNG transparency.
π Debugging Tips
- If nothing appears, check: Is the image transparent? Maybe use box-shadow instead.
- Try increasing blur-radius for smoother edges.
- Shadows on white backgrounds may appear faint β tweak color opacity.
- Stack multiple shadows for better depth.