CSS box shadows are one of the most powerful tools in a web designer's arsenal. They add depth, visual hierarchy, and a polished feel to otherwise flat elements — and they're supported in every modern browser. Whether you're building a subtle card layout or a dramatic hero section, understanding box-shadow is essential.
In this guide, we'll break down the complete box-shadow syntax, walk through real-world examples, share performance best practices, and show you how to use a box shadow generator to speed up your workflow.
box-shadow Property?The box-shadow property attaches one or more drop shadows to an element. Unlike text-shadow, it applies to the entire box model of an element (including padding and border, but not margin). It doesn't affect layout — shadows are painted outside the element's content flow, so they won't push siblings around.
Browser support is universal: every browser since IE9 supports the basic syntax, and inset shadows work everywhere modern CSS is expected.
The full syntax looks like this:
box-shadow: [inset] [offset-x] [offset-y] [blur-radius] [spread-radius] [color];
Every part except offset-x and offset-y is optional. Let's define each value:
| Value | Required | Description |
|---|---|---|
inset | No | Makes the shadow render inside the element instead of outside. |
offset-x | Yes | Horizontal distance. Positive = right, negative = left. |
offset-y | Yes | Vertical distance. Positive = down, negative = up. |
blur-radius | No | How much the shadow spreads and softens. 0 = sharp edge. Higher = softer. Defaults to 0. |
spread-radius | No | Grows or shrinks the shadow. Positive = bigger, negative = smaller. Defaults to 0. |
color | No | Shadow color. If omitted, defaults to currentColor (usually black). |
The bread and butter of modern UI design. A subtle shadow that lifts an element slightly off the page:
.card {
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
0 2px 4px -2px rgba(0, 0, 0, 0.1);
}
This two-layer approach creates a more natural look than a single shadow. The first layer provides a wider ambient shadow, while the second adds a tighter contact shadow.
Neumorphism uses both outer and inset shadows to create a soft, extruded look — popular in dashboard and settings UIs:
.neu-card {
background: #1a1d2e;
box-shadow: 9px 9px 16px #b8bec7,
-9px -9px 16px #ffffff;
}
.neu-inset {
background: #1a1d2e;
box-shadow: inset 5px 5px 10px #b8bec7,
inset -5px -5px 10px #ffffff;
}
Multiple shadows stacked at the same position create a vivid glow effect — great for buttons and CTAs:
.glow-btn {
box-shadow: 0 0 15px rgba(99, 102, 241, 0.4),
0 0 45px rgba(99, 102, 241, 0.2),
0 0 80px rgba(99, 102, 241, 0.1);
}
A sharp, offset shadow with no blur creates a striking brutalist aesthetic:
.brutal {
box-shadow: 6px 6px 0 #1a1a2e;
border: 2px solid #1a1a2e;
}
Use CSS transitions to animate the shadow on hover, creating an interactive lift effect:
.float-card {
transition: box-shadow 0.3s ease, transform 0.3s ease;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.float-card:hover {
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
transform: translateY(-4px);
}
Pure black (#000) looks harsh and unnatural. Always use rgba() with low alpha values (0.05–0.25) for subtle, realistic shadows. Darker shadows on light backgrounds, lighter on dark.
rgba(0, 0, 0, 0.1) as your starting point and adjust from there. Most professional UI shadows sit between 0.05 and 0.2 alpha.A single shadow creates a flat look. Stacking two or three shadows at different blur and offset values produces a much more convincing sense of depth. Material Design's elevation system uses this technique extensively.
Blur radii above 40–50px start to look muddy and can hurt performance. If you need a very soft, wide shadow, use a large spread radius with moderate blur instead.
On white backgrounds, dark gray shadows look natural. On colored backgrounds, tint the shadow with a complementary or analogous hue for a cohesive look. For example, on a blue background, try rgba(0, 50, 150, 0.2).
Box shadows are generally well-optimized by browsers, but there are a few things to keep in mind:
opacity on a pseudo-element with the shadow, or animate transform for movement.will-change: box-shadow sparingly. Only apply it right before an animation starts, and remove it after.Manually tweaking six different values to get the perfect shadow is tedious. A good box shadow generator lets you:
This is where the RiseTop Box Shadow Generator comes in — a free, browser-based tool designed for speed and precision.
CSS also offers filter: drop-shadow(), which follows the alpha channel of the element. Use box-shadow for rectangular or border-radius shapes. Use drop-shadow() when you need the shadow to match irregular shapes (like PNG images with transparency or non-rectangular clip-paths).
/* Box shadow: follows the rectangular box */
.icon-box {
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
/* Drop shadow: follows the actual shape (great for PNGs) */
.icon-shape {
filter: drop-shadow(0 4px 12px rgba(0,0,0,0.15));
}
Shadows should enhance usability, not undermine it. Keep these points in mind:
outline for keyboard users./* Subtle card */
box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
/* Medium elevation */
box-shadow: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
/* High elevation */
box-shadow: 0 10px 25px rgba(0,0,0,0.1), 0 6px 10px rgba(0,0,0,0.08);
/* Inset */
box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
/* Glow */
box-shadow: 0 0 20px rgba(99,102,241,0.3);
/* Hard (brutalist) */
box-shadow: 5px 5px 0 #1a1a2e;
/* Neumorphism */
box-shadow: 8px 8px 16px #d1d5db, -8px -8px 16px #ffffff;
CSS box shadows are a small property with outsized impact. From subtle card elevations to dramatic glow effects, they're the difference between a page that feels flat and one that feels alive. Master the syntax, understand layering, use a generator to iterate faster, and always keep performance in mind.
Use the RiseTop Box Shadow Generator — a free, interactive tool to design, preview, and copy production-ready CSS box shadows in seconds.
Back to Blog · RiseTop — Free CSS Tools for Designers & Developers