Short answer: box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); — horizontal offset, vertical offset, blur radius, color. That's 90% of what you'll ever write. The full syntax adds an optional spread radius and an inset keyword, and you can stack several shadows with commas.
Each value, in plain English
- offset-x (required): how far the shadow sits left or right of the element. Positive pushes it right.
- offset-y (required): how far it sits up or down. Positive pushes it down.
- blur-radius (optional): how soft the shadow's edge is. 0 gives a hard, crisp edge.
- spread-radius (optional): how much the shadow grows or shrinks beyond the element's box. Positive makes it bigger all around.
- color (optional): any CSS color. Leave it out and the shadow uses your text color — which surprises everyone the first time.
- inset (optional): flips the shadow inside the element instead of outside it.
.card {
/* offset-x | offset-y | blur | spread | color */
box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.15);
}Why real shadows need two layers
Look at any shadow in the physical world and it has two parts: a small, darker, sharper shadow right where the object meets the surface, and a larger, fainter, softer one spreading beyond it. A single box-shadow can only imitate one of those, which is why one-shadow cards look flat and fake no matter how you tune the numbers. CSS lets you stack shadows with commas — and the standard professional recipe is exactly the physical one: a tight contact shadow (small offset, small blur, higher opacity) layered over an ambient shadow (larger offset, large blur, low opacity). Every recipe in this post is built that way, and once you see shadows as two layers with two jobs, the values stop being guesswork: contact shadows stay small because contact is small, ambient shadows grow as the element's imagined height grows.
Stacking multiple shadows
Separate shadows with commas — the first one in the list renders on top. Layering a small tight shadow under a large soft one is how you get depth that looks real instead of a single grey smudge:
.card {
box-shadow:
0 1px 2px rgba(0, 0, 0, 0.08),
0 8px 24px rgba(0, 0, 0, 0.12);
}Inset: shadows on the inside
Put inset first and the shadow draws inside the element's frame — pressed buttons, sunken form fields, inner depth on cards:
.button:active {
/* shadow moves inside: the button looks pressed */
box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.25);
}An elevation scale you can steal
Interfaces need consistency more than they need any single perfect shadow: a card, a dropdown, and a modal should read as three heights of the same system. A simple three-step scale, each step two layers, covers nearly everything:
/* Low — cards, list items */
.raised-1 {
box-shadow: 0 1px 2px rgba(0,0,0,0.07), 0 4px 12px rgba(0,0,0,0.06);
}
/* Medium — dropdowns, popovers */
.raised-2 {
box-shadow: 0 2px 4px rgba(0,0,0,0.08), 0 12px 28px rgba(0,0,0,0.10);
}
/* High — modals, dialogs */
.raised-3 {
box-shadow: 0 4px 8px rgba(0,0,0,0.10), 0 24px 48px rgba(0,0,0,0.14);
}Notice the pattern as height grows: the ambient layer's offset and blur grow a lot, its opacity grows a little, and the contact layer barely changes. That is the physics showing through — a higher object casts a wider, softer shadow, while its contact point stays a contact point. Shadows also pair naturally with translucency: a floating panel with a soft shadow over a blurred backdrop is the core of How to Create the Glassmorphism Effect with CSS, and it only reads as glass because the shadow sells the height.
Two recipes to copy
/* Subtle card lift */
.card {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card:hover {
transform: translateY(-2px);
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16);
}
/* Soft glow */
.glow {
box-shadow: 0 0 24px rgba(59, 130, 246, 0.45);
}Common mistakes and how to fix them
- One shadow doing both jobs. Cause: a single mid-blur, mid-opacity shadow asked to be contact and ambient at once. Fix: split it into two layers — tight and dark underneath the element's edge, wide and faint beyond it — as in the stacking section.
- Pure black shadows at high opacity. Cause: defaulting to rgba(0,0,0,0.4) or stronger. Fix: real shadows on white surfaces rarely exceed about 0.15–0.2 total. On colored backgrounds, tint the shadow toward the background's hue instead of using neutral black, which reads as dirt.
- Shadow on the wrong element. Cause: applying the shadow to a wrapper while the visible card is a child with its own background. Fix: the shadow follows the box of the element it is declared on — put it on the element whose edges the user actually sees.
- Animating the shadow for hover on long lists. Cause: box-shadow is paint-expensive, and animating it on dozens of rows repaints constantly. Fix: animate transform and opacity where you can, and reserve shadow transitions for individual interactive elements like cards and buttons.
- Negative spread surprises. Cause: spread shrinks the shadow before blur is applied, and large negative values can make it vanish entirely. Fix: that vanishing is sometimes the goal — a shadow visible only at the bottom uses a negative spread equal to the blur — but reach for it deliberately, not by accident.
The traps
- Color left out: with no color, the shadow takes your text color. Black text gives a black shadow — usually not what you wanted. Set the color explicitly.
- Blur of 0 looks broken: box-shadow: 4px 4px 0 black is a hard offset block, not a soft shadow. A valid style, but rarely the one people meant.
- Clipped by overflow: a parent with overflow: hidden cuts the shadow off at its edges. If your shadow vanishes, check the ancestors.
- No layout space: shadows paint outside the element without moving anything — neighbors won't make room, so large blurs can overlap surrounding content.
- Heavy blurs everywhere: big blur radii on dozens of elements cost paint performance. Keep decorative shadows modest.
Frequently asked questions
What is the difference between box-shadow and drop-shadow()? box-shadow follows the element's rectangular box — a transparent PNG inside it still casts a rectangle. The filter function drop-shadow() follows the actual alpha shape of the content, so the same PNG casts a shadow shaped like the image. Use box-shadow for cards and panels, drop-shadow() for irregular shapes and icons — and note drop-shadow() has no spread or inset.
Can a shadow appear on only one side? Yes, with the negative-spread technique: set the spread to the negative of the blur radius and offset toward the side you want — the shadow shrinks on the other three sides until only the offset side escapes. box-shadow: 0 10px 12px -8px rgba(0,0,0,0.2) gives a bottom-only shadow, a common trick under sticky headers.
Why does my shadow look different in dark mode? Because a dark shadow on a dark background is nearly invisible — depth in dark interfaces usually comes from lighter edges and background steps, not shadows. Many design systems reduce shadow opacity drastically or drop shadows entirely in dark mode and let a subtle border do the separating.
Does border-radius affect the shadow? Yes — the shadow follows the element's border box including its rounded corners, which is exactly why card shadows look right without extra work. Change the radius and the shadow's corners follow automatically.
Try it
Dial in the exact shadow visually with the Box Shadow Generator — offsets, blur, spread, and color with a live preview, then copy the CSS straight into your stylesheet.