- Home
- Tools
- Color & Design
- Box Shadow Generator
Box Shadow Generator
Stack and tune CSS box shadows by eye, then copy the code.
Presets
What the values do
box-shadow:
0 4px 12px -2px rgba(0, 0, 0, 0.15);
From left to right: the offset to the right, the offset down, the blur, the spread and the color. Only the two offsets are required.
| Value | What it does |
|---|---|
| Offsets | Move the shadow. A positive second value pushes it down, as if the light came from above; negative values go left and up. |
| Blur | Softens the edge. At 0 the edge is sharp. The fade is about twice as wide as the number and sits half inside and half outside the edge, so a blur of 12px fades over roughly 24px. It cannot be negative. |
| Spread | Makes the shadow larger on every side before it is blurred, or smaller when negative. A negative spread with a downward offset gives a shadow that only shows under the box. |
| Color | Without one the shadow takes the text color. Black at 10 to 25% opacity is the usual choice on a light page. |
inset | Draws the shadow inside the box, so the box looks pressed in instead of lifted. |
The shadow follows the corners of the box, including its border-radius, and takes up no room: nothing around the box moves because of it.
Why several faint layers look better than one dark one
Hold your hand just above a table and the shadow is small and crisp. Lift it and the shadow grows wider and paler. A real object casts all of that at once: dark and tight where it touches the surface, soft further out.
One box-shadow has one blur, so it is either tight or soft. Stacking layers that each reach a little further and blur a little more gets close to the real thing. The Layered soft preset doubles offset and blur with every layer, from 1px to 16px, each at 7% black. Right at the edge of the box, where all five overlap, they add up to almost 30% (1 − 0.93⁵). Four pixels further out the shadow is half as dark, and at the far end only the widest layer is left, fading out from 7%.
In the list, the first layer is painted on top of the ones below it. That matters once layers have different colors or an inset layer is mixed in.
On dark backgrounds
A shadow darkens what is behind it, and a nearly black page has little left to darken. Dark interfaces usually show height with a slightly lighter surface or a thin border instead. The preview shows a light page on purpose: judge the shadow on the page it will go on, not on a dark background.
Cost
A blurred shadow is drawn again whenever the box changes size or the shadow changes, and a larger blur takes longer to draw. A shadow on a handful of cards is nothing to worry about. Large blurs on hundreds of elements, or a box-shadow that is animated, can make scrolling and transitions stutter on slower devices. For a hover effect, put the bigger shadow on a pseudo-element and fade its opacity in, which the browser can do without redrawing the shadow.
Shapes that are not boxes
box-shadow only knows the box. For a transparent PNG, an SVG icon or anything cut out with clip-path, use a filter, which follows the visible outline:
filter:
drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
drop-shadow() has no spread and no inset, and it takes one shadow at a time: write the function several times, separated by spaces, to stack them.