CSS drop-shadow() Filter

Theory & Explanation

drop-shadow() is a CSS filter function that applies a shadow effect to the rendered image, shape, or element, including its alpha (transparency) channel. Unlike box-shadow, which is applied to the element's box, drop-shadow() follows the visible shape, making it ideal for images with transparency, SVGs, and icons.

Key differences from box-shadow:

Use drop-shadow() to create realistic shadows for images, icons, and custom shapes, especially when transparency is involved. Experiment with color and blur for creative effects. For UI elements like cards or buttons, box-shadow is usually preferred.

Code Examples

.basic-drop-shadow {
  filter: drop-shadow(4px 4px 8px #888);
}

.colored-drop-shadow {
  filter: drop-shadow(0 8px 16px #8e44ad);
}

.multiple-drop-shadow {
  filter: drop-shadow(2px 2px 4px #3498db) drop-shadow(-2px -2px 4px #ffd200);
}

.interactive-drop-shadow:hover {
  filter: drop-shadow(0 8px 24px #f7971e) drop-shadow(0 0 8px #ffd200);
}

.transparent-drop-shadow {
  filter: drop-shadow(0 8px 16px #3498db);
}

Live Demos

Image with a basic drop-shadow effect Unsplash Portrait PNG Unsplash Portrait PNG Unsplash Portrait PNG
← Back to Home