CSS / Reference / box-shadow: Offsets, Blur, Spread, and Inset Shadows
box-shadow paints a shadow outside or inside an element’s box. Each shadow requires a horizontal and vertical offset. Blur and spread are optional, and the shadow leaves the box’s size and the positions of nearby elements unchanged.
box-shadow syntax and value order
Read the lengths as x y [blur] [spread]. The brackets indicate optional values and are omitted from the CSS. Put 0 in the third position if you want to set a spread while keeping a sharp edge.
| Value | Effect |
|---|---|
x y |
Horizontal and vertical offsets. Positive values move the shadow right and down. Negative values move it left and up. |
blur |
The third length. Zero makes a hard edge and larger values soften it. A negative blur radius is invalid. |
spread |
The fourth length. Positive spread expands an outer shadow and negative spread contracts it. For an inset shadow, positive spread makes it reach farther into the box. |
color |
Defaults to the element’s currentColor. Use an alpha color such as rgb(0 0 0 / 25%) to control opacity separately from the text color. |
inset |
Paints the shadow inside the box. Omit inset to paint it outside. |
, |
Separates multiple shadows. Each shadow is painted over the shadows listed after it. |
none |
The initial value removes every shadow. The property is not inherited. |
The shadow follows rounded corners defined by border-radius. See CSS Backgrounds and Borders — box-shadow for the reference edges used to paint outer and inset shadows.
Compare an outer shadow with an inset shadow
Save the complete example as box-shadow.html in UTF-8 and open it in a browser. The boxes stack if the window is narrow. Select .outer and .inner in the developer tools to inspect their rules.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>box-shadow comparison</title>
<style>
body { margin: 0; color: #20242b; background: #fff; font: 16px/1.7 system-ui, sans-serif; }
main { padding: 24px; max-width: 820px; margin: auto; }
h1 { font-size: 22px; margin: 0 0 20px; }
.samples { display: flex; flex-wrap: wrap; gap: 24px; }
.sample { width: min(264px, 100%); }
.stage { display: flow-root; }
.label { margin: 0 0 8px; font-weight: 700; }
.box {
box-sizing: border-box;
width: min(236px, calc(100% - 28px));
height: 136px;
margin: 14px;
padding: 18px;
background: #bfe3ff;
}
.outer { box-shadow: 4px 6px 12px 2px rgb(0 0 0 / 25%); }
.inner { box-shadow: inset 0 0 0 3px #006c9c; }
</style>
</head>
<body>
<main>
<h1>box-shadow comparison</h1>
<div class="samples">
<div class="sample">
<p class="label">Outer shadow</p>
<div class="stage"><div class="box outer">Box shadow</div></div>
</div>
<div class="sample">
<p class="label">inset inner shadow</p>
<div class="stage"><div class="box inner">Box shadow</div></div>
</div>
</div>
</main>
</body>
</html>
A soft gray shadow extends to the lower right of the first box. The second has a crisp blue strip 3 pixels wide just inside its edge. Toggle each declaration in the developer tools and watch the shadow disappear while the box retains its dimensions.
Change blur, spread, and stacking order
- Change the
12pxblur on.outerto0. Its edge becomes sharp at the same offset. Restore12px. - Change the
2pxspread on.outerto-2px. The painted area contracts and the edge stays soft. Restore2px. - Change the spread on
.innerfrom3pxto6px. The blue strip grows thicker inside the box while the box keeps its size.
Replace the .outer declaration with the one below. Both shadows have zero offset and blur, so you can compare their color and spread directly.
.outer {
box-shadow: 0 0 0 3px #006c9c, 0 0 0 7px #b3daf0;
}
A 3-pixel dark band sits right against the box with a lighter band outside it. Reverse the two values and the opaque 7-pixel shadow covers the narrower one because the first shadow in the list is painted on top.
Find out why an outer shadow is clipped
If a shadow ends along a straight line, check that the element has a computed shadow, then inspect its ancestors for overflow. In the example, set overflow: hidden or overflow: clip on the .stage containing .outer. The portion that extends beyond the clipping edge disappears. Disable the overflow rule to see it again.
If the contents need clipping, put the shadow on an outer wrapper and apply the clipping rule to a separate element inside it. For the differences between clipping and scrolling, see the CSS overflow guide.
Choose a shadow for a box, text, or transparent image
Use box-shadow around a card or button, and text-shadow around the characters in a heading. A shadow on a rounded card follows the card’s corner shape.
Use filter: drop-shadow() if the shadow should follow the visible pixels of a transparent logo or icon. The filter accepts offsets, blur and color. It has no spread or inset argument. See Filter Effects — drop-shadow() for the function’s syntax.





