CSS Box-Shadow Guide: Syntax, Layered Shadows & Realistic Depth
September 28, 2026 | 10 min read | CSS
By Syed · Frontend Engineer & Creator of UITweak
Shadows are what separate flat, amateur-looking interfaces from polished, professional ones. Yet most developers use a single generic shadow everywhere, box-shadow: 0 4px 6px rgba(0,0,0,0.1), and wonder why their UI still looks cheap. In this guide you will learn the full box-shadow syntax, how to layer multiple shadows for realistic depth, and the soft-shadow technique used by top design teams.
Shortcut: don't want to hand-write values? Use our free Shadow Studio , adjust everything visually and copy the CSS in one click.
1. Box-Shadow Syntax, Explained
The full syntax looks like this:
box-shadow: [inset] offset-x offset-y blur-radius spread-radius color;offset-x/offset-y, how far the shadow moves horizontally and vertically. Positive Y pushes it down (light comes from above).blur-radius, how soft the shadow edge is.0gives a hard, solid edge; larger values fade it out.spread-radius, grows (+) or shrinks (-) the shadow's size before blurring.color, almost always black with low alpha, e.g.rgba(0, 0, 0, 0.12). Never use pure opaque black, it looks muddy.inset(optional), puts the shadow inside the element instead of outside. Great for pressed inputs and inner depth.
2. Layer Multiple Shadows for Realism
Real-world shadows are never a single flat blur, they have a dark, tight core near the object and a wide, faint ambient falloff. You can comma-separate multiple shadows on one element to fake this:
.card {
box-shadow:
0 1px 2px rgba(0, 0, 0, 0.06), /* tight contact shadow */
0 4px 12px rgba(0, 0, 0, 0.08), /* mid-range depth */
0 12px 32px rgba(0, 0, 0, 0.10); /* soft ambient falloff */
}The first shadow in the list renders on top. Stack a small dark one first, then progressively larger and fainter ones. This one trick instantly makes cards, modals, and dropdowns look expensive.
3. The Soft-Shadow Recipe
Harsh shadows scream "default Tailwind". For the soft, premium look:
- Use a large blur (24–64px) with low opacity (0.08–0.15).
- Add a negative spread (e.g.
-12px) so the giant blur doesn't leak too far sideways. - Tint the shadow color toward your background, on dark UIs use
rgba(0,0,0,0.5); on light UIs a warmrgba(60, 40, 20, 0.12)often looks more natural than neutral black.
.hero-card {
box-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.18);
}4. Inset Shadows for Pressed & Inner Depth
The inset keyword flips the shadow inside the element, perfect for input fields, pressed buttons, and neumorphic panels:
.input {
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
}
.input:focus {
box-shadow:
inset 0 2px 4px rgba(0, 0, 0, 0.06),
0 0 0 3px rgba(99, 102, 241, 0.25); /* focus ring */
}Notice the focus ring is just another layered shadow with 0 blur, a handy pattern for accessible focus states without extra elements.
5. Shadows in Tailwind CSS
Tailwind ships with shadow-sm through shadow-2xl, plus arbitrary values for custom work:
<!-- custom layered shadow, arbitrary value -->
<div class="shadow-[0_1px_2px_rgba(0,0,0,0.06),0_12px_32px_rgba(0,0,0,0.10)]">
...
</div>Underscores become spaces inside arbitrary values. For colored shadows, Tailwind also supports shadow-indigo-500/20 style color/opacity modifiers.
6. Common Mistakes to Avoid
- Same shadow on everything. Vary elevation: cards low, modals high, tooltips medium. A consistent elevation scale beats random values.
- Shadows on dark backgrounds. Black shadows disappear on dark UIs, use borders, glows (
0 0 24px rgba(99,102,241,0.35)), or lighter surface colors instead. - Animating box-shadow directly. It triggers repaints and janks. Animate
opacityof a pseudo-element shadow, or usetransformfor movement. - Forgetting border-radius.Shadows follow the element's shape, mismatched radius makes them look broken.
7. Copy-Paste Shadow Presets
/* Subtle card */
--shadow-card: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);
/* Floating modal */
--shadow-modal: 0 8px 16px rgba(0,0,0,0.10), 0 24px 64px rgba(0,0,0,0.16);
/* Glow (dark UI accent) */
--shadow-glow: 0 0 24px rgba(99, 102, 241, 0.45);
/* Pressed / inset */
--shadow-pressed: inset 0 2px 6px rgba(0,0,0,0.12);8. Box Shadow Hover Effects
A shadow that deepens on hover makes any card feel interactive. The key is transitioning box-shadow itself, which is fine for hover (it only repaints on state change, not every frame like a loop):
.card {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: box-shadow 0.25s ease, transform 0.25s ease;
}
.card:hover {
box-shadow:
0 4px 12px rgba(0, 0, 0, 0.10),
0 16px 40px rgba(0, 0, 0, 0.14);
transform: translateY(-4px);
}Pair the deeper shadow with a small lift. Either one alone feels flat; together they sell the illusion that the card rises toward the cursor. Design these visually in our free box shadow CSS generator.
Debugging: five reasons your shadow is invisible
One, an ancestor with overflow: hidden, auto, or scroll is clipping it. This is the cause more often than the other four combined. Find it by setting overflow: visible on ancestors one at a time until the shadow appears. Two, the shadow color matches the surface behind it. A black shadow at 10 percent opacity on a near-black card is technically there; you just cannot see it. Three, the element has display: contents. That removes the box, and box-shadow needs a box. The fix is to move the shadow to a child that actually generates one. Four, a sibling with a higher stacking order is painting over the part of the shadow that extends past the element's edge. Shadows paint below the element's own background but above whatever sits behind the element, so a positioned sibling can cover them. Five, the values collapsed: a large negative spread with a small blur can shrink the shadow to nothing, and inset puts it inside where you might not be looking. Check the overflow ancestor first. It is almost always the overflow ancestor.
A shadow system that survives dark mode
The mistake is defining one shadow scale and hoping it works on both themes. Black shadows vanish on dark surfaces, so a dark theme needs its own elevation language. Mine has two parts. On light backgrounds, the standard layered black shadows from section 2. On dark backgrounds, I drop shadows almost entirely and use borders plus surface lifts: a 1px border in white at 8 to 12 percent opacity, and a lighter surface color for the raised element. Where a glow is needed, a colored shadow at low opacity works on both themes because it reads as light, not as occlusion.
:root {
--shadow-raised: 0 1px 2px rgb(0 0 0 / 0.08), 0 8px 24px rgb(0 0 0 / 0.12);
--edge-raised: 1px solid rgb(0 0 0 / 0.08);
}
[data-theme="dark"] {
--shadow-raised: 0 0 0 rgb(0 0 0 / 0);
--edge-raised: 1px solid rgb(255 255 255 / 0.10);
}
.card {
box-shadow: var(--shadow-raised);
border: var(--edge-raised);
}Setting the dark shadow to a transparent zero keeps the token shape identical, so components never branch. The border does the elevation work on dark, the shadow does it on light.
Performance: where shadows actually cost you
Static shadows are cheap. The browser paints them once and caches the result. The cost appears in three situations. First, animating box-shadow in a loop. Every frame repaints the shadow, which is one of the most expensive things you can ask the paint step to do. The standard replacement is a pseudo-element carrying the end-state shadow, with its opacity animated instead. Opacity is composited; the shadow itself never repaints. Second, large blurs on many elements at once. A 64px blur on one hero card is fine. The same blur on fifty list rows forces fifty large paint regions, and scrolling starts to stutter on mid-range phones. Keep big blurs for a few hero elements. Third, shadows on elements inside scroll containers that repaint constantly. If the content repaints every frame anyway, the shadow cost is noise. If the list is static, the shadow is painted once and forgotten. Profile with the paint flashing tool in DevTools before optimizing. Most shadow performance advice is premature, but these three cases are real.
FAQ
How do I use the CSS box-shadow property?
The syntax is box-shadow: offset-x offset-y blur-radius spread-radius color. A basic example: box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) puts a soft shadow 4px below the element. Add inset at the start for an inner shadow, and comma-separate multiple shadows to layer them.
How do I apply multiple box shadows on one element?
Comma-separate them: box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.10). The first shadow renders on top, so list the tight dark core first and the wide faint falloff last. See section 2 above for the full layering recipe.
When should I use box-shadow vs other depth techniques?
Use box-shadow for elevation on light UIs: cards, modals, dropdowns. On dark backgrounds switch to borders or glows, since black shadows disappear. For shadows that follow irregular shapes (like PNG cutouts), use filter: drop-shadow() instead, it traces the alpha channel rather than the box.
Why does my box-shadow look different in every browser?
Blur rendering varies slightly between engines, but big differences usually mean something else: a parent with overflow: hidden clipping the shadow, or a missing border-radius making it look wrong. Fix the clipping first before blaming the browser.
Design shadows visually, skip the guesswork
Shadow Studio lets you tune offsets, blur, spread, color, opacity, and layers with live preview, then copies production-ready CSS or Tailwind classes.
Open Shadow Studio, it's free