Layering Multiple CSS box-shadows for a Natural Shadow
CSS box-shadow accepts several comma-separated shadows, so you can layer them. If you stack several light shadows, from small offsets and blurs up to large ones, the shadow is darkest right under the card and fades as it moves away. This works well for card layouts, modals (dialogs), and dropdown menus whose shadow looks like a blurry gray band.
My test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and headless Chromium 153. I placed a white card (240×120px, 8px border radius) on a white background, gave it a black shadow, and took a screenshot with Playwright. I calculated darkness from the red channel of each pixel as 1 − value/255, which gives a number from 0 to 1. I did not test Firefox, Safari, real smartphones, or how inset shadows look.
- 1. Separate shadows with commas; the first one is drawn on top
- 2. Comparing one shadow with five stacked shadows
- 3. Blur values and how far a shadow reaches
- 4. Use a negative spread to keep shadows off the sides and top
- 5. Shadows take no space, and overflow: hidden clips them
- 6. Animating between different numbers of shadows
Separate shadows with commas; the first one is drawn on top
box-shadow takes a horizontal offset, a vertical offset, a blur, a spread, and a color. As described on MDN's box-shadow page, you can add several shadows by separating them with commas.
To check the stacking order, I added two opaque shadows with no blur.
.card {
box-shadow:
8px 8px 0 #00c8e8, /* light blue */
16px 16px 0 #d85878; /* pink */
}
The pixel where the two shadows overlap was light blue (rgb(0,200,232)). When I swapped the order, the same pixel became pink (rgb(216,88,120)). The shadow written first is drawn on top. The specification (CSS Backgrounds and Borders Module Level 3) also says the first shadow is on top and the rest are painted behind it.
When semi-transparent shadows overlap, they get darker. I added one shadow of 0 0 0 10px rgb(0 0 0 / 0.5), and the darkness just outside the card was 0.502. With two of the same shadow, it was 0.753. This matches the calculation 1 − 0.5 × 0.5 = 0.75, where a 0.5 layer is placed over another 0.5 layer.
Comparing one shadow with five stacked shadows
I compared one large shadow with five stacked shadows that increase from small to large. For the five shadows, I doubled the vertical offset and blur each time: 1px, 2px, 4px, 8px, and 16px. All of them were black with a darkness of 0.08.
/* One shadow */
.card-single {
box-shadow: 0 16px 16px rgb(0 0 0 / 0.34);
}
/* Five stacked shadows */
.card-layered {
box-shadow:
0 1px 1px rgb(0 0 0 / 0.08),
0 2px 2px rgb(0 0 0 / 0.08),
0 4px 4px rgb(0 0 0 / 0.08),
0 8px 8px rgb(0 0 0 / 0.08),
0 16px 16px rgb(0 0 0 / 0.08);
}
The darkness of 0.34 for the single shadow matches the darkest point when five layers of 0.08 are stacked (1 − 0.92⁵ ≈ 0.34). I also set the offset and blur of the single shadow to 16px, the same as the largest of the five.

I measured the darkness at every 2px below the bottom edge, at the horizontal center of the card. I picked out the following values.
| Distance below the bottom edge | One shadow | Five stacked shadows |
|---|---|---|
| 0px | 0.333 | 0.322 |
| 4px | 0.318 | 0.153 |
| 8px | 0.282 | 0.098 |
| 16px | 0.161 | 0.035 |
| 24px | 0.043 | 0.008 |
| 32px | 0.004 | 0 |

The darkness right under the card is about 0.33 in both cases, so it is nearly the same. The difference is what happens after that. With one shadow, the darkness is still 0.282 at 8px, so the dark band continues for a while before it fades. With five stacked shadows, the darkness at 4px is 0.153, about half, and after that a faint shadow continues for a long distance. The right edge of the card shows the same pattern. At 2px outside, one shadow measured 0.125 and five stacked shadows measured 0.055.
The small shadows (0 1px 1px and 0 2px 2px) add darkness only right next to the card's edge. The large shadow (0 16px 16px) covers the faint part that reaches far away. In this comparison, a single shadow could not give both strong darkness at the edge and a long, faint shadow at the same time, so I split the shadow into several layers.
Blur values and how far a shadow reaches
When you choose a blur value, it helps to know how far the shadow reaches, because that makes it easier to decide the margin around the element. I measured the darkness outward from the right edge of the card for 0 0 20px #000, a shadow with no offset.
| Distance from the right edge | Darkness |
|---|---|
| 0px | 0.478 |
| 10px | 0.141 |
| 20px | 0.012 |
| 24px | 0 |
The blur section of the specification says that the blur is close to a Gaussian blur whose standard deviation is half of the blur value. It also notes that the color changes over a width of about twice the blur value, centered on the shadow's edge. My measurements agree: at the edge the darkness was about half (0.478), and at 20px outward, which is the same as the blur value, it was almost 0. So you can estimate the margin by assuming the shadow reaches outward from its offset position by about the blur value.
Use a negative spread to keep shadows off the sides and top
If you set the fourth length (spread) to a negative value, the shadow becomes smaller than the card. When the shadow is offset downward, a negative spread reduces how far it extends to the sides and top.
.card {
box-shadow: 0 12px 16px -8px rgb(0 0 0 / 0.3);
}
I compared this with 0 12px 16px rgb(0 0 0 / 0.3), which has no spread, and got these results.
| Measured position | No spread | Spread -8px |
|---|---|---|
| 2px above the top edge | 0.008 | 0 |
| 2px right of the right edge | 0.114 | 0.031 |
| 8px below the bottom edge | 0.2 | 0.09 |
The side shadow dropped to about a quarter, and the top shadow disappeared. The shadow below also became about half as dark.
Shadows take no space, and overflow: hidden clips them
A shadow does not affect the size of its element or the scrolling of its parent. I placed the card inside a parent that is 320px wide and 160px high with overflow: auto, and gave the card a large 0 0 0 100px shadow. The card stayed 240×120px, and the parent's scrollWidth and scrollHeight stayed at 320 and 160. No scrollbars appeared. The specification's section on layering and layout also says that shadows do not affect layout and do not extend the scrollable area.
Because shadows take no space, if the parent has overflow: hidden, any part of the shadow that extends outside the parent is clipped and disappears. I tested this by placing the five-layer card inside a parent with no fixed height.
.list {
overflow: hidden;
}
The bottom edge of the parent lined up with the bottom edge of the card, and the darkness at 2px, 6px, and 12px below the card was 0 in each case. When I removed overflow: hidden, the shadow showed darkness of 0.212, 0.122, and 0.059 at those positions.
If you cannot remove overflow: hidden, add padding to the parent so there is room for the shadow.
.list {
overflow: hidden;
padding: 24px;
}
With padding: 24px, there is a 24px margin below the card, and the darkness at 2px, 6px, and 12px below returned to 0.212, 0.122, and 0.059, the same as without overflow: hidden. Based on the previous section, if the largest shadow is 0 16px 16px, the shadow reaches about 32px below the bottom edge of the card (16px offset plus 16px blur). Use this 32px as the guide for the padding. With the 24px in this example, anything beyond that is clipped. However, in my measurements of the five-layer shadow, the darkness beyond 24px below the bottom edge was 0.008 or less, which is barely visible.
Animating between different numbers of shadows
When a card's shadow grows on hover, the normal state and the raised state may have different numbers of shadows. I animated a change from one shadow to two stacked shadows using the Web Animations API, paused it midway, and read the values with getComputedStyle().
.card {
box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
transition: box-shadow 200ms ease-out;
}
.card:hover {
box-shadow:
0 4px 8px rgb(0 0 0 / 0.2),
0 16px 32px rgb(0 0 0 / 0.2);
}
I changed between the two values above over one second. The values I read at the start were as follows.
rgba(0, 0, 0, 0.2) 0px 1px 2px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px
The missing second shadow was filled in as a transparent shadow with no offset and no blur. At the halfway point, the values were as follows. The first shadow gradually grew larger, and the second shadow gradually became darker from transparent.
rgba(0, 0, 0, 0.2) 0px 2.5px 5px 0px, rgba(0, 0, 0, 0.1) 0px 8px 16px 0px
MDN also says that when the number of shadows differs, the shorter list is padded with transparent shadows at the end before interpolation. So you can animate smoothly even if you do not write the same number of shadows in each state.
However, if only one side has inset, the values are not interpolated. When I animated from 0 1px 2px to inset 0 4px 8px with the Web Animations API, the value stayed at the start until 40%, and it switched to the end value at 50%. MDN also says that when one value has inset and the other does not, the change happens without animation, and the value jumps to the new one. For how to write the lift-on-hover motion itself, see the separate article, "How to Add a Lift Effect to a Card on Hover with CSS."





