To use css box-shadow, write box-shadow: offset-x offset-y blur-radius spread-radius color; on the element. For example, box-shadow: 0 4px 12px rgba(0 0 0 / 0.2); draws a soft shadow four pixels below the box. The shadow follows the element's border box, including rounded corners, and it never changes the layout.
You can stack several shadows separated by commas, make a shadow render inside the box with the inset keyword, and animate it with transitions. This guide covers each value, then builds the common patterns: cards, focus rings and layered depth.
A shadow takes up to four lengths, a color and an optional inset keyword:
| Value | Meaning in the example |
|---|---|
| Horizontal offset | 2px moves the shadow right (negative moves it left) |
| Vertical offset | 4px moves the shadow down (negative moves it up) |
| Blur radius | 8px softens the edge; 0 gives a hard edge, and it cannot be negative |
| Spread radius | 1px grows the shadow on all sides (negative shrinks it) |
| Color | rgba(0 0 0 / 0.25) is black at 25 percent opacity |
The first two lengths are required. Blur and spread are optional, and spread can only be written if blur is also written. If you leave out the color, the browser uses the element's color value (currentcolor), so it is best to always set it explicitly.
Shadows look natural when they imply light from above. A small positive vertical offset with a larger blur reads as "raised". Equal offsets in both directions read as a diagonal light.
The second rule has zero blur, which produces the flat, retro "sticker" look often used in neo-brutalist designs.
Blur and spread are easy to confuse. Blur controls how soft the edge is. Spread controls how large the shadow shape is before blurring.
blur-only produces a glow around all sides.spread-only produces a solid ring six pixels wide. This is a popular way to draw a focus ring that does not affect layout, unlike border.negative uses a negative spread so the shadow is smaller than the box and only shows below it, giving a tight, realistic drop shadow.Adding the keyword inset draws the shadow inside the border, making the element look pressed in or recessed.
The inset keyword can go first or last in the value, but not between the lengths. Inset shadows paint above the background but below the content, so text and child elements are not covered.
Separate shadows with commas. The first shadow in the list is painted on top.
Real shadows are not one uniform blur. Stacking a tight, a medium and a wide shadow with low opacity gives a smoother, more natural depth than one heavy shadow. You can also mix an outer shadow with an inset one, for example a drop shadow plus a light inner highlight on a button.
A card with a hover lift uses a transition on box-shadow:
For keyboard focus, a spread-only shadow works well, but note that shadows are removed in Windows High Contrast and forced-colors modes. If you replace the default outline, keep a transparent outline as a fallback so focus stays visible:
box-shadow forces repaints. For many elements, put the large shadow on a pseudo-element and animate its opacity instead.box-shadow follows the rectangular box (with border-radius). For the outline of a transparent PNG or SVG, use the filter: drop-shadow() function, covered in the article on filters.text-shadow instead. box-shadow on an inline element shadows each line box, which rarely looks right.overflow: hidden.Yes. Use a negative spread equal to the blur and offset toward the side you want, for example box-shadow: 0 8px 8px -8px rgba(0 0 0 / 0.4); shows a shadow on the bottom edge only.
A parent with overflow: hidden or overflow: auto clips anything painted outside its box. Add padding to the parent or remove the overflow rule so the shadow has room.
box-shadow shadows the rectangular border box. filter: drop-shadow() shadows the actual rendered shape, including transparent areas of images and clipped elements.
No. It is purely visual and does not change the element's size or push other elements, so it also does not trigger layout when it changes.
box-shadow takes offsets, an optional blur and spread, a color and an optional inset. Use small vertical offsets and low-opacity colors for realistic depth, stack several shadows for smoother results, and use a zero-blur spread shadow for focus rings. Remember that shadows ignore layout, can be clipped by overflow, and are costly to animate on large areas.