Understanding Modern Box Shadows in UI Design
Dive deep into CSS box shadows — from soft layered tokens to glassmorphism and inset depth techniques. Learn how shadows communicate elevation, hierarchy, and feel.
UIXplor Team
February 20, 2026 · 7 min read
01What Makes a Great Shadow?
A great shadow doesn't just sit beneath an element — it tells a story. It communicates how high off the surface an object floats, how much light hits it from above, and whether it's interactive. The difference between a flat card and a beautifully elevated card is almost always the shadow.
Modern UI design has moved away from harsh, dark box-shadows toward layered, diffused shadows that feel more physically plausible. Instead of one thick shadowy layer, we stack two or three with increasing blur radius and decreasing opacity — mimicking how real light actually scatters.
02The Layered Shadow Technique
The layered approach is the gold standard for soft, realistic shadows. Here's the formula:
Small contact shadow — a tight, low-blur shadow right beneath the element simulates the contact point where the element 'almost touches' the surface.
Medium ambient shadow — a wider, more diffused layer mimics the ambient light bleeding around the object.
Optional wide halo — for high-elevation elements, a very wide, almost invisible shadow creates atmosphere.
Here's a practical example:
.card {
box-shadow:
0 1px 2px rgba(0, 0, 0, 0.04), /* contact */
0 4px 12px rgba(0, 0, 0, 0.06), /* ambient */
0 16px 40px rgba(0, 0, 0, 0.04); /* halo */
}This combination is imperceptible individually but stunning together.
03Shadows on Dark Backgrounds
This trips up even experienced designers. On a dark background, a shadow of `rgba(0,0,0,0.3)` is essentially invisible — you're making something darker than dark. The solution is to use white glow instead of dark shadow.
For dark UI cards, use:
.dark-card {
box-shadow:
0 4px 12px rgba(255, 255, 255, 0.06),
0 0 0 1px rgba(255, 255, 255, 0.04);
}The second shadow is a 1px hairline ring that adds a subtle border-elevation without a hard `border` property. This technique is used by Linear, Vercel, and GitHub's dark interfaces.
04Inset Shadows for Depth
While most shadows push elements *up*, inset shadows carve them *in*. This creates a pressed, recessed, or indented effect — perfect for input fields, pressed buttons, or "well" containers.
.input-dark {
box-shadow:
inset 0 1px 2px rgba(255, 255, 255, 0.08),
inset 0 -1px 2px rgba(0, 0, 0, 0.4);
}Notice the top inset uses a white tint (simulating light from above casting into the well) and the bottom uses black (shadow at the bottom of the cavity). This creates a convincing recessed look.
05Glassmorphism Shadows
Glassmorphism goes beyond `backdrop-filter: blur()`. The shadows are critical to making glass feel real. A glass element has:
1. No traditional box shadow — the frosted surface doesn't cast a hard shadow 2. A subtle inner highlight — the top edge catches light 3. A soft outer glow — the frosted surface diffuses ambient light around it
.glass-card {
background: rgba(255, 255, 255, 0.08);
backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.2),
inset 0 1px 0 rgba(255, 255, 255, 0.2);
}The `inset 0 1px 0` creates the catching-light effect on the top edge — this is the subtle detail that separates premium glassmorphism from amateur attempts.
06Using Design Tokens for Shadow Systems
Rather than writing shadows ad hoc, define a shadow scale that maps to elevation levels. This creates visual consistency across your entire UI:
:root {
--shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
--shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
--shadow-md: 0 4px 16px rgba(0,0,0,0.08);
--shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
--shadow-xl: 0 16px 64px rgba(0,0,0,0.12);
}Use `--shadow-xs` for subtle hover feedback. `--shadow-md` for cards. `--shadow-xl` for modals and overlays. The discipline of a shadow token system prevents shadow chaos in large codebases.
07Best Practices Summary
1. Layer instead of single — two or three subtle layers beat one heavy shadow 2. Match light source — shadows should fall consistently in one direction 3. Dark mode needs white glow — not dark shadow 4. Insets feel interactive — use for inputs, pressed states, wells 5. Use tokens — define a shadow scale, stick to it 6. Glassmorphism needs both — outer blur shadow AND inset top highlight
Shadows are invisible design elements that make everything feel real. Spend time learning them and your UIs will have an unmistakable sense of depth and polish.
Related UI Components
Related Articles