Presets
Shadow Layers
box-shadow: 0 4 12 0 rgba(0,0,0,0.15);
Understanding the CSS box-shadow Property
The box-shadow property is one of the most versatile CSS features for adding depth and dimension to UI elements. It accepts up to six values: horizontal offset, vertical offset, blur radius, spread radius, color, and the optional inset keyword. Each shadow creates a blurred copy of the element's border box, offset and optionally spread.
Shadows are drawn in reverse order — the first shadow in the list appears on top. This lets you layer soft ambient shadows with sharper directional shadows for realistic depth. Modern browsers support box-shadow with excellent performance, and it works seamlessly with border-radius.
Using Multiple Shadows for Realistic Depth
Professional designs often combine multiple shadow layers. A common pattern is a soft, large blur for ambient light plus a smaller, darker shadow for directional depth. For example: box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.08).
Colored shadows can add brand personality — a subtle tint matching your accent color creates cohesion. Glow effects use zero offset with a large blur and semi-transparent color. Our generator lets you add and remove layers, adjust each independently, and see the result in real time.
Box Shadow Performance and Best Practices
box-shadow is GPU-accelerated in modern browsers and does not trigger layout reflow. However, animating box-shadow can be expensive because the browser must repaint the shadow every frame. For hover or transition effects, consider using transform or opacity instead, or limit shadow complexity.
Avoid stacking many shadows on a single element — three or fewer layers is usually sufficient. Use rgba() or hsla() for color so you can control opacity without affecting the shadow's visual weight. Test on lower-end devices if your UI relies heavily on shadows.
Design Best Practices for Shadows
Shadows should reinforce hierarchy and affordance. Cards and modals benefit from subtle elevation; buttons can use a light shadow that increases on hover. Keep shadows consistent across your design system — define a small set of elevation levels (e.g., sm, md, lg) and reuse them.
Match shadow direction to your light source. If your UI implies light from above, shadows should drop downward. Softer, larger blurs feel more natural than harsh, small blurs. For dark themes, consider lighter shadows (e.g., rgba(255,255,255,0.05)) instead of pure black to avoid muddy results.
Frequently Asked Questions
Related Tools
Explore More Tools
Find this tool useful? Buy us a coffee to keep DuskTools free and ad-light.