Good to know
Reading a shadow value
box-shadow: [inset] x y blur spread colour;
- x and y move the shadow right and down; negative values move it left and up.
- blur softens the edge. Browsers draw it as a Gaussian blur whose standard deviation is half the blur value, so a bigger number gives a wider, softer edge.
- spread grows the shadow before it is blurred (positive) or shrinks it (negative). A negative spread with a large Y offset gives a shadow that only peeks out at the bottom.
- colour is written as
rgb(0 0 0 / 10%), where the last number is the Opacity % slider. At 100% the plain hex colour is used. - inset draws the shadow inside the edge, which reads as pressed or sunken.
Why stack layers
A real object casts a tight, darker shadow close to it and a wide, faint one further out. Two or three layers imitate that. The Layered preset is a good model:
box-shadow: 0px 1px 2px 0px rgb(0 0 0 / 6%),
0px 4px 8px 0px rgb(0 0 0 / 6%),
0px 12px 24px -4px rgb(0 0 0 / 10%);
Layers are painted in reverse order, so the first one in the list sits on top.
Practical notes
- A shadow follows the
border-radiusof its box, which is why the output includes it. Copy both lines. - Shadows take up no space in the layout. A parent with
overflow: hiddencan cut a large one off, so leave room around the element. - On a dark background a black shadow barely shows. A lighter card colour, a thin border or a soft coloured glow (see the Glow preset) shows depth better.
- Animating large blurred shadows on many elements at once can make scrolling less smooth on older phones.