CSS Box Shadow Generator
Build one box-shadow rule at a time: set the horizontal and vertical offsets, blur, spread, colour and optional inset, then copy the result. Real shadows usually need two or three layers, so generate each layer separately and join the rules with a comma.
How to design a box shadow
-
1
Set the shadow values
Horizontal offset, vertical offset, blur radius, spread, and colour with opacity.
-
2
Toggle inset
Flip the shadow to inset for an inner shadow: useful for pressed buttons and cavity effects.
-
3
Choose the colour
Black with low opacity is the classic. Coloured shadows (matching the element's hue, darker) read more naturally.
-
4
Copy the CSS
Copy the single shadow rule and paste it into your stylesheet. For layered shadows, generate each layer separately and join the rules with a comma.
The box-shadow syntax
box-shadow: <x-offset> <y-offset> <blur> <spread> <colour> [inset];
- x-offset: positive = right, negative = left.
- y-offset: positive = down, negative = up.
- blur: 0 = hard edge, higher = softer. Visible size is roughly 1.5x blur beyond the element.
- spread: extra size beyond the element. Positive grows the shadow; negative shrinks it (useful for subtle halos).
- colour: supports any CSS colour.
rgba(0, 0, 0, 0.15)is the bread and butter. - inset: keyword flipping the shadow inside the element.
Layered shadows look real
This generator outputs one shadow rule at a time, so to build a layered shadow, generate each layer separately and combine the rules with a comma.
One shadow with 0 0 40px looks hazy. Two shadows, a small sharp one close to the element and a larger soft one further out, mimic how real light scatters.
box-shadow:
0 1px 2px rgba(0, 0, 0, 0.08),
0 4px 12px rgba(0, 0, 0, 0.08);
The first line gives the tight contact shadow; the second the softer ambient. This single pattern covers 80% of card-style UI.
Elevation systems
Material Design uses 6 elevation levels, each a different shadow stack. Simplified:
| Elevation | Shadow |
|---|---|
| 1 (resting) | 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24) |
| 2 | 0 3px 6px rgba(0,0,0,.16), 0 3px 6px rgba(0,0,0,.23) |
| 3 | 0 10px 20px rgba(0,0,0,.19), 0 6px 6px rgba(0,0,0,.23) |
| 4 (lifted) | 0 14px 28px rgba(0,0,0,.25), 0 10px 10px rgba(0,0,0,.22) |
| 5 (floating) | 0 19px 38px rgba(0,0,0,.30), 0 15px 12px rgba(0,0,0,.22) |
Pick one per elevation role and use it consistently.
Coloured shadows read more naturally
Pure black shadows look artificial because real shadows are tinted by the surface below them. Try:
box-shadow: 0 12px 24px rgba(40, 80, 120, 0.18);
- a cool blue-grey instead of pure black. On warm backgrounds, use a warmer tint.
Performance
Box-shadows are painted on every repaint. Large, heavy shadows on many elements can slow scrolling. Mitigations:
- Use
transform: translateZ(0)on the element to force a composite layer. - Replace complex shadows with
filter: drop-shadow()only if you need the shadow to follow a clip-path (it is slower in general). - Limit shadows on elements that re-render frequently.
Inset for pressed states
.button:active {
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.12);
}
Inset shadows fake a recessed look, the button appears pressed into the surface. Combine with a small downward transform: translateY(1px) for a tactile click.
Frequently Asked Questions
Usually because blur is too low or spread is too high. A hard-edged shadow with no blur looks like a duplicate element. Increase blur (20-30px is a common starting point) and keep spread at 0 or very small negative values.
Box-shadow follows the element’s border-box, including border-radius, so rounded cards get nicely rounded shadows automatically. For clip-path shapes, box-shadow does not follow the clip; use filter: drop-shadow() instead.
Offset the shadow heavily in the chosen direction and use negative spread to hide the opposite side. Or use two shadows, one visible on the target side, another with negative spread to “eat” the unwanted spill.
No hard limit, but each shadow is another paint pass. Three to four layers is the practical ceiling; anything more and you should consider using a background image or SVG instead.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.