Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

box-shadow — CSS box shadows

The box-shadow property adds one or more outer or inner shadows to an element’s box without changing its layout dimensions. Each shadow can have its own offset, blur, spread, and color.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

box-shadow: none | <shadow>#;
<shadow> = <color>? && [<length>{2} <length [0,∞]>? <length>?] && inset?

box-shadow paints shadows of the box, not the outlines of letters or an image’s opaque pixels. Its initial value is none, and it is not inherited. Shadows occupy no layout space. Their shape accounts for border-radius.

In the Level 3 syntax shown here, the two required lengths specify horizontal and vertical offsets: positive values move the shadow right and down. The third length is the blur radius, which cannot be negative; the fourth is spread, which can be negative. Omitted blur and spread are 0. Percentages are not allowed. An omitted color defaults to currentColor. The optional inset keyword changes an outer shadow into an inner shadow.

Separate shadows with commas; the first is painted above the others. Outer shadows are below the element’s background, while inner shadows are above the background but below content. Blur does not guarantee identical pixels across implementations, so the example uses sharp edges.

Level 4 describes box-shadow as a shorthand for component properties and extends its grammar. This entry and example deliberately use Level 3 syntax; inclusion in a specification draft does not establish browser support for extensions. The example still requires local verification.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>box-shadow</title>
<style>
  body { margin: 40px; background: white; }
  .box {
    width: 120px;
    height: 80px;
    background: white;
    box-shadow: inset 0 0 0 4px navy, 8px 8px 0 0 teal;
  }
</style>
<div class="box"></div>
</html>

Result

A white 120 × 80 CSS-pixel box with a 4px navy inner edge and a sharp teal outer shadow offset 8px right and 8px down. No text or console output.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources