CSS Box Shadow Generator · Tutorial
How to create realistic layered shadows for cards
7 min readintermediateUpdated
A single dark box shadow makes your cards look heavy and dated. This tutorial builds a soft three-layer shadow that looks like real light, previews it on your page colour, and creates a raised hover state.
What you need
- The CSS Box Shadow Generator
- Your page and card colours, or the sample from the Try it button
Steps
Start with the sample layers
The sample has three layers, all a dark blue-grey at low opacity: a 1 px shadow with 2 px blur for the contact edge, a 4 px shadow with 8 px blur, and a 16 px shadow with 32 px blur for the soft spread of light.
Match your design
Set Page colour to your background and Box colour to your card colour, and give the box the same corner radius as your cards. Shadows look softer on white and stronger on grey backgrounds.
Understand the negative spread
The two larger layers use a negative spread, -2 px and -8 px. That pulls the shadow in at the sides, so the blur shows mainly below the card, as it would under light from above.
Copy the resting shadow
Press Copy and add the CSS to your card style. Keep opacity low; layered shadows add up, and three layers at 6–14% already look substantial.
Make a hover state
Increase the down offset and blur of the largest layer, for example to 24 px and 48 px, copy the new CSS, and use it for
:hover. Add a transition so the card lifts smoothly..card { transition: box-shadow 200ms ease, transform 200ms ease; } .card:hover { transform: translateY(-2px); box-shadow: /* paste the stronger shadow here */; }Respect reduced motion
Wrap the transform in
@media (prefers-reduced-motion: no-preference)so people who turn off animations still get the shadow change without movement.
Try it yourself
Opens the CSS Box Shadow Generator with this tutorial's sample loaded.
Common mistakes
- Pure black at high opacity
- Black shadows at 30% or more look dirty. Use a dark tint of your text or background colour at low opacity.
- Shadows on all sides
- Shadows with no vertical offset look like a glow, not elevation. Keep a small downward offset.
- Animating box-shadow on many items
- On long lists, animating shadows can stutter on slow phones. For heavy pages, fade in a pre-shadowed pseudo-element instead.
Next steps
Go back to the CSS Box Shadow Generator, or keep going with one of these:
FAQ
How many layers is too many?
Two or three are enough for nearly every design. More layers rarely look different but cost a little more to draw.
Can I use the shadow on images?
Yes, box-shadow works on images and any element. For a shadow that follows a transparent PNG’s shape, use filter: drop-shadow() instead.