What box-shadow draws
The CSS box-shadow property paints one or more shadows around an element, or inside it with the inset keyword. Each shadow is a copy of the box’s outline, including its rounded corners, moved, blurred and grown or shrunk, then filled with a color.
Shadows take up no room in the layout, so adding one never pushes other elements around. A parent with overflow: hidden can cut them off, though, which is worth knowing when a shadow seems to stop at an edge.
The parts of a shadow
The two offsets move the shadow right and down; negative values move it left and up. Blur softens the edge, and 0 gives a hard edge. Spread grows the shape before it is blurred, or shrinks it with a negative value, which keeps a wide blur from showing at the sides.
Several shadows are separated by commas, and the first one is painted on top. A common pattern pairs a small, darker shadow close to the box with a wide, faint one further away.
box-shadow: [inset] x y blur spread color; 0 12px 32px -8px rgba(15, 23, 42, 0.18) x 0 no sideways shift y 12px 12px down, as if lit from above blur 32px a soft edge spread -8px 8px smaller on every side color dark blue-grey at 18% opacity
Shadows in a design system
Shadows work best as a small, fixed scale of elevation levels rather than a new value for every component. Name the levels, keep them as tokens and use the same few everywhere, so cards, menus and dialogs read as part of one interface.
On dark backgrounds shadows barely show. Many dark themes raise elements with a slightly lighter surface instead and keep shadows for separation where they are still visible.
- Define three or four elevation levels as tokens and reuse them
- Tint shadows toward the background’s hue instead of pure black
- Pair a tight, darker layer with a wide, faint one
- Check the shadow on the real background color, not only on white
- Hand developers the CSS with the token name next to it