CSS box-shadow Property Explained

What the CSS box-shadow property does, with an example.

Published November 4, 2026

box-shadow adds one or more shadows around an element: offset-x offset-y blur spread color. The inset keyword draws the shadow inside.

How it works

Multiple shadows are comma-separated and layered. Soft, low-opacity shadows look more natural than dark ones.

Shadows do not affect layout.

Values and effects

box-shadow: 0 2px 4px rgba(0,0,0,.2); → subtle lift
box-shadow: 0 10px 30px rgba(0,0,0,.25); → floating card
box-shadow: inset 0 0 0 2px #2f81f7; → inner outline
box-shadow: 0 0 0 3px rgba(47,129,247,.4); → focus ring

Practical examples

Card

.card { box-shadow: 0 4px 12px rgba(0,0,0,.15); }

Layered shadow

.card { box-shadow: 0 1px 2px rgba(0,0,0,.1), 0 8px 24px rgba(0,0,0,.12); }

Focus ring

input:focus { box-shadow: 0 0 0 3px rgba(47,129,247,.4); outline: none; }

Common mistakes

  • Huge blur values hurting performance.
  • Removing outline without providing a focus indicator.
  • Using fully black, heavy shadows.

Key takeaways

  • box-shadow in one line: box-shadow adds one or more shadows around an element: offset-x offset-y blur spread color.
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

Box-shadow vs drop-shadow?

drop-shadow filter follows the shape of transparent images; box-shadow uses the rectangular box.

Is box-shadow supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles