X Xerobit

CSS Box Shadow Generator

Stack multiple box-shadow layers with live preview. Configure x/y offset, blur, spread, color, and inset flag per layer. Copy CSS.

Preview
CSS output
 

box-shadow syntax explained

The box-shadow property accepts up to six values. Understanding each one lets you craft exactly the shadow you want:

box-shadow: [inset] offset-x offset-y blur-radius spread-radius color;
/* Example */
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
ParameterWhat it doesTip
insetMakes shadow inside the elementUse for pressed/sunken effect
offset-xHorizontal distanceNegative = left
offset-yVertical distanceNegative = up
blur-radiusHow blurry/soft the shadow is0 = sharp edge
spread-radiusExpand or contract shadow sizeNegative shrinks
colorShadow colorUse rgba for transparency

The five box-shadow parameters

An optional inset keyword flips the shadow inward, simulating an inner glow or recessed effect.

Realistic shadows: use multiple layers

Real depth comes from stacking 2-4 subtle shadows rather than one big one. Try:

Multi-layer box shadow recipes

Copy any of these directly into your CSS or use them as starting points in the generator above:

/* Subtle card lift (Google Material style) */
box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);

/* Hard shadow (flat design) */
box-shadow: 4px 4px 0 #000;

/* Colored glow */
box-shadow: 0 0 20px rgba(99, 102, 241, 0.6);

/* Inner sunken effect */
box-shadow: inset 0 2px 4px rgba(0,0,0,.2);

/* Elevation system (3 levels) */
--shadow-sm: 0 1px 2px rgba(0,0,0,.05);
--shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
--shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);

The elevation system approach — defining shadow tokens at three levels — is particularly useful in design systems where you want consistent depth cues across components.

box-shadow vs drop-shadow() filter

These two CSS features look similar but behave very differently:

Rule of thumb: for cards and divs, use box-shadow. For icons and images with transparent backgrounds, use filter: drop-shadow().

Frequently asked questions

Why is my box-shadow being clipped?

A parent element with overflow: hidden will clip any shadow that extends beyond its bounds. Remove overflow: hidden from the parent, or switch to filter: drop-shadow() which is not affected by overflow clipping. This is one of the most common box-shadow debugging issues.

Does box-shadow affect layout?

No. Shadows are purely visual and do not take up space in the layout — they don't affect the size or position of other elements. If you need a visible border that does affect layout, use border. If you need a layout-aware outline that doesn't shift surrounding elements, use outline with outline-offset.

How do I animate a box-shadow on hover?

Declare the shadow on both the base state and the hover state, then add transition: box-shadow 0.2s ease to the base element. The browser will interpolate between the two values smoothly:

.card {
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  transition: box-shadow 0.2s ease;
}
.card:hover {
  box-shadow: 0 8px 20px rgba(0,0,0,.2);
}

Avoid animating other properties alongside box-shadow if performance is a concern — shadow transitions can be GPU-intensive on complex pages.

Designing with shadow: best practices

Shadows communicate depth and elevation. Using them well means following a few conventions that keep interfaces looking professional rather than dated:

Use low opacity, not dark colors

Shadows built with rgba(0, 0, 0, 0.1) or similar low-opacity black values look natural on any background color. Using a fully opaque gray like #999 creates muddy-looking shadows that clash on non-white backgrounds. Keep opacity between 0.05 and 0.25 for realistic results. Pick the right hue using the color picker.

Match shadow direction consistently

In real life, light comes from above. Shadows should point downward — meaning your offset-y is positive. Mixing upward and downward shadows on the same page creates visual confusion. Pick one light source direction and stick to it across all components.

Scale shadow with elevation

Elements at different visual heights should cast different shadows. A floating action button sits higher than a card, which sits higher than a flat list item. Larger blur-radius and offset-y values signal higher elevation. Define a small set of shadow tokens (sm, md, lg) and apply them consistently to maintain a coherent depth hierarchy.

Don't stack too many shadows

Two to three layers is usually the sweet spot for realistic multi-layer shadows. Beyond that, the effect rarely adds perceptible depth and increases rendering cost. The most convincing material-style shadows use one close, sharp layer (low blur, low offset) and one diffuse, distant layer (high blur, higher offset).

box-shadow and accessibility

Shadows are a visual-only cue and do not communicate meaning to screen readers. Never use shadow alone to indicate state changes such as focus or selection — always pair it with a color change, border, or outline. For keyboard focus indicators in particular, outline is more reliable than box-shadow because some high-contrast modes in operating systems suppress shadow rendering but preserve outlines.

Related tools

Related articles

Further reading

Pillar

Part of Frontend & Design.


Written by Mian Ali Khalid. Last updated 2026-05-12.