The CSS box-shadow property adds one or more shadow effects around an element's box. Shadows are essential for creating depth, elevation and visual separation in modern UI design — buttons, cards, modals, dropdowns and tooltips all rely on them. Unlike image-based shadows, CSS box shadows are crisp at any resolution, load instantly, and can be animated.
Use the generator above to build single or multi-layer shadows visually, then copy the CSS directly into your project.
box-shadow: offset-x offset-y blur spread color; box-shadow: inset offset-x offset-y blur spread color; /* Multiple layers (comma-separated) */ box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 8px 24px rgba(0,0,0,0.15);
offset-x — Horizontal shadow position. Positive moves right, negative moves left.
offset-y — Vertical shadow position. Positive moves down, negative moves up.
blur-radius — How soft the shadow edge is. 0 = sharp. Higher = more diffused.
spread-radius — Expands or contracts the shadow size. Positive = larger than the element. Negative = smaller.
color — The shadow color. Use rgba() to control opacity.
/* Subtle card lift */ box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.08); /* Elevated modal */ box-shadow: 0 8px 32px rgba(0,0,0,0.24), 0 2px 8px rgba(0,0,0,0.12); /* Soft bottom shadow only */ box-shadow: 0 4px 16px -4px rgba(0,0,0,0.2); /* Coloured glow */ box-shadow: 0 0 0 1px #7c6fff, 0 0 20px rgba(124,111,255,0.4); /* Pressed button (inset) */ box-shadow: inset 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 2px rgba(0,0,0,0.2); /* No shadow (reset) */ box-shadow: none;
The inset keyword moves the shadow inside the element boundary — useful for pressed button states, inner glow effects, and UI elements that need to appear recessed into the surface.
/* Input field focus ring using inset */
.input:focus {
box-shadow:
inset 0 1px 3px rgba(0,0,0,0.15),
0 0 0 3px rgba(124,111,255,0.25);
}
/* Inner glow */
.glow-card {
box-shadow: inset 0 0 30px rgba(124,111,255,0.2);
}
An inner shadow is simply a box-shadow with the inset keyword. To put the inner shadow on only one side, offset it towards that side and use a negative spread equal to the blur, so it doesn’t show on the other edges:
/* Inner shadow on all sides */ box-shadow: inset 0 0 10px rgba(0,0,0,0.5); /* Inner shadow on the top only */ box-shadow: inset 0 8px 8px -8px rgba(0,0,0,0.5); /* Inner shadow on the bottom only */ box-shadow: inset 0 -8px 8px -8px rgba(0,0,0,0.5); /* Inner shadow on the left and right */ box-shadow: inset 8px 0 8px -8px rgba(0,0,0,0.5), inset -8px 0 8px -8px rgba(0,0,0,0.5); /* Inner and outer shadow together */ box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.15);
Tip: turn on Inset for a layer in the generator above to preview any inner shadow before copying it.
Real-world objects cast complex shadows with multiple components — a sharp close shadow and a soft diffuse shadow further away. Layering two shadows closely mimics this and produces much more realistic depth than a single layer.
/* Layered realistic shadow (low elevation) */
.card {
box-shadow:
0 1px 2px rgba(0,0,0,0.07),
0 2px 4px rgba(0,0,0,0.07),
0 4px 8px rgba(0,0,0,0.07);
}
/* High elevation — modal/dialog */
.modal {
box-shadow:
0 2px 4px rgba(0,0,0,0.08),
0 8px 16px rgba(0,0,0,0.1),
0 24px 48px rgba(0,0,0,0.12);
}
box-shadow can be transitioned, but it is expensive because it triggers a repaint on every frame. For animated hover effects, a performance trick is to pre-render the shadow using opacity: 0 on a pseudo-element and fade that in instead of transitioning box-shadow directly.
/* Simple transition (OK for occasional use) */
.card {
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transition: box-shadow 0.25s ease;
}
.card:hover {
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
A normal shadow shows on every side the blur reaches. To show it on one side only, push it out with the offset and pull it back in with a negative spread roughly the size of the blur. The negative spread shrinks the shadow so it can’t peek out of the other three edges.
/* Bottom only */ box-shadow: 0 8px 6px -6px rgba(0,0,0,0.35); /* Top only */ box-shadow: 0 -8px 6px -6px rgba(0,0,0,0.35); /* Right only */ box-shadow: 8px 0 6px -6px rgba(0,0,0,0.35); /* Left only */ box-shadow: -8px 0 6px -6px rgba(0,0,0,0.35); /* Top and bottom only (two layers) */ box-shadow: 0 8px 6px -6px rgba(0,0,0,0.35), 0 -8px 6px -6px rgba(0,0,0,0.35);
Increase the offset to make the shadow longer, and keep the spread at about minus the blur so the sides stay clean. This is the usual way to add a shadow under a sticky header or navbar.
A shadow with no offset, no blur and a positive spread draws a solid ring around the element. Unlike a real border, it takes up no space, so adding or animating it never shifts the layout.
/* 2px ring outside the element */ box-shadow: 0 0 0 2px #7c6fff; /* 2px ring inside the element */ box-shadow: inset 0 0 0 2px #7c6fff; /* Two rings: white gap, then colour */ box-shadow: 0 0 0 2px #fff, 0 0 0 4px #7c6fff; /* Bottom "border" only */ box-shadow: inset 0 -2px 0 #7c6fff;
box-sizing: border-box.border-radius, can stack several rings and animates smoothly on hover.overflow: hidden. The shadow is drawn outside the element and gets clipped. Give the parent some padding, or move the shadow to the parent.position: relative and a z-index to the element with the shadow.0 needs a unit (4px, not 4), and multiple shadows must be separated by commas.border-radius of the element it’s on. If the rounding is on a child, such as an image, add the same radius to the element with the shadow.<span> or <a> the shadow wraps each line separately. Use display: inline-block or block.box-shadow only accepts a single colour per layer, so it can’t be a gradient. For a coloured, gradient glow, put a blurred gradient behind the element with a pseudo-element:
.card {
position: relative;
isolation: isolate; /* keeps the glow behind this card only */
border-radius: 16px;
background: #fff;
}
.card::after {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
background: linear-gradient(135deg, #7c6fff, #ff6fb0);
filter: blur(20px);
transform: translateY(8px);
}
Tailwind CSS includes ready-made shadow-* utilities, and shadow-none removes a shadow. The exact sizes in the scale differ between Tailwind versions, so check the docs for the one you use. Any shadow from this generator works as an arbitrary value, with underscores in place of spaces:
<div class="shadow-[0_8px_24px_rgba(0,0,0,0.12)]">...</div>
React Native traditionally doesn’t use CSS box-shadow. On iOS you set shadowColor, shadowOffset, shadowOpacity and shadowRadius; on Android you set elevation. Newer React Native versions also accept a boxShadow style, so check what your version supports.
box-shadow has been universally supported since 2011 — completely safe to use without prefixes or fallbacks. It respects border-radius, but does NOT follow clip-path shapes (use filter: drop-shadow() for that).
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| box-shadow | 10+ | 4+ | 5.1+ | 12+ |
| inset shadows | 10+ | 4+ | 5.1+ | 12+ |
| multi-layer | 10+ | 4+ | 5.1+ | 12+ |
| box-shadow animation | 26+ | 16+ | 7+ | 12+ |
Stack two shadows with opposite directions — one dark below-right, one light above-left, both on a background that matches the element. Example: box-shadow: 8px 8px 16px #b8b9be, -8px -8px 16px #ffffff. The element should share the same background color as its parent for the soft, embedded look.
Default (outset) shadows project outward from the element's edge. Adding the inset keyword flips the shadow inward, making the element appear pressed in or recessed. Inset shadows are useful for input field focus rings, pressed button states and recessed UI panels.
Use a small Y offset, a large blur radius, and low opacity: box-shadow: 0 8px 24px rgba(0,0,0,0.08). The key is high blur with low opacity. Stack a second tighter shadow for added depth: box-shadow: 0 8px 24px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.06).
Yes, but it's expensive — animating box-shadow forces a repaint every frame. For smooth performance, animate the opacity of a pseudo-element with the shadow on it, or use transform: scale() to fake elevation changes. The Animating box-shadow section above has the optimized pattern.
Use box-shadow for rectangular UI elements (cards, buttons, panels) — it's faster and respects border-radius. Use filter: drop-shadow() for irregular shapes — it follows transparent areas in PNGs and clip-path edges, which box-shadow can't do. For most UI work, box-shadow is the right choice.
Comma-separate them in a single box-shadow declaration. Each shadow renders top-down — the first shadow listed appears on top. Layering 2-4 shadows produces realistic depth: a tight inner shadow for the edge plus a wider outer shadow for ambient elevation.
Offset the shadow downwards and use a negative spread about the size of the blur, so it can’t show on the other sides: box-shadow: 0 8px 6px -6px rgba(0,0,0,0.35).
Yes. box-shadow: 0 0 0 2px #7c6fff draws a 2px ring that takes up no space, so it never shifts the layout. Add inset to draw it inside the element instead.
The most common causes are a parent with overflow: hidden clipping it, a neighbouring element painted on top, a shadow too faint for the background, or a missing unit such as 4 instead of 4px.
Set box-shadow: none. In Tailwind CSS, use the shadow-none class.
Not directly, because each shadow layer takes one colour. Place a blurred gradient behind the element with a ::after pseudo-element instead.
Need a shadow that follows the actual shape of an element rather than its bounding box? Use our CSS Filter Generator with drop-shadow() instead.
Copy-paste shadows for the most common UI components. Paste directly into your project — all use rgba() for compatibility with both light and dark backgrounds.
box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
box-shadow: 0 8px 32px rgba(0,0,0,.22), 0 2px 8px rgba(0,0,0,.12);
box-shadow: 0 4px 14px rgba(124,111,255,.4), 0 1px 4px rgba(0,0,0,.12);
box-shadow: 0 0 0 3px rgba(124,111,255,.3), 0 1px 3px rgba(0,0,0,.1);
box-shadow: 0 2px 6px rgba(0,0,0,.1), 0 8px 24px rgba(0,0,0,.08);
box-shadow: 0 0 0 1px #7c6fff, 0 0 20px rgba(124,111,255,.5);
box-shadow: inset 0 1px 3px rgba(0,0,0,.15), inset 0 1px 1px rgba(0,0,0,.1);
box-shadow: 0 1px 2px rgba(0,0,0,.07), 0 4px 8px rgba(0,0,0,.07), 0 12px 24px rgba(0,0,0,.07);