Codectionary / Developer documentation / CSS

box-shadow

box-shadow adds one or more drop shadows to an element's box, accepting horizontal offset, vertical offset, blur radius, optional spread radius, and color. The inset keyword flips the shadow to render inside the element instead of outside. Multiple shadows can be layered by comma-separating values, useful for realistic elevation effects.

Syntax

box-shadow: offsetX offsetY blur spread color;

Examples

A Basic Drop Shadow

The standard elevated-card look.

.card {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  /* offsetX offsetY blur color */
}

.elevated {
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

Inset Shadow and Layered Shadows

An inner shadow, and combining multiple shadows for realistic depth.

.pressed {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.layered {
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.07),
    0 4px 8px rgba(0, 0, 0, 0.07),
    0 8px 16px rgba(0, 0, 0, 0.07);
}

Parameters and values

  • offsetX / offsetY (length): Horizontal and vertical shadow position
  • blur (length): How soft/spread out the shadow edge is
  • spread (length): Expands or shrinks the shadow size before blurring
  • inset (keyword): Renders the shadow inside the element instead of outside

Best practices

  • Use low-opacity black (rgba(0,0,0,0.1) or similar) rather than solid gray for more natural-looking shadows
  • Layer multiple subtle shadows rather than one large one for a more realistic, soft elevation effect (a common design-system pattern)
  • Use inset shadows for pressed/active button states or input field focus effects
  • Keep shadow intensity proportional to elevation - small, subtle shadows for slightly-raised cards, larger and softer ones for modals and popovers

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation