Multiple Box Shadows
What you'll learn: How to apply multiple shadows to a single element by layering them with commas, creating rich visual depth and complex lighting effects.
Layering Shadows
Just as a real object in the world might cast multiple shadows when lit by different light sources, CSS lets you apply several box-shadow values to one element. Instead of being limited to a single shadow, you can comma-separate multiple shadow declarations.
How it works: Each shadow in the list is rendered independently, and they stack from first to last. The first shadow you write appears on top, and each subsequent shadow is layered beneath the previous one.
The Syntax
.card {
box-shadow:
0 2px 4px rgba(0, 0, 0, 0.1),
0 8px 16px rgba(0, 0, 0, 0.2);
}
In this example, two shadows are applied:
- The first (subtle, close) appears on top
- The second (larger, softer) appears beneath it
This creates a more realistic depth effect than a single shadow could achieve.
Practical Applications
Think of multiple shadows like layers of tracing paper, each adding its own contribution to the final effect. You might combine:
- A tight inner shadow with a loose outer glow
- Different colored shadows for creative effects
- Inset shadows mixed with standard outer shadows
.button {
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.5),
0 2px 4px rgba(0, 0, 0, 0.3);
}
The order matters! Rearranging your comma-separated list changes which shadows are visible on top.
Key Takeaway: Multiple box shadows are comma-separated and stack with the first shadow on top, allowing you to create sophisticated lighting effects by layering simple shadows together.