CSS propertyEffects

box-shadow

Adds a shadow around an element, outside or inside.

Initial value
none
Inherited
No
Animatable
yes, as a list of shadows
Applies to
all elements
JavaScript
element.style.boxShadow = "0 10px 30px rgba(0,0,0,.4)"
On this page

Example

#
CSS
.card {
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 12px 32px -8px rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 20px 48px -8px rgba(124, 58, 237, 0.45);
}
Preview

Definition and usage

#

The box-shadow property draws a shadow in the shape of the element’s box, respecting the border-radius rounding. You provide the horizontal and vertical offset, the blur, the spread and the colour.

The inset keyword draws the shadow inside, giving a recessed effect. Several shadows separated by commas let you build realistic depth: a small sharp shadow close to the element and a large soft one further away.

A shadow takes up no space in the layout, so it doesn’t push other elements around. That is why it is sometimes used instead of a border, for example box-shadow: 0 0 0 2px #a78bfa.

Syntax

#
Syntax
box-shadow: none | inset? <offset-x> <offset-y> <blur>? <spread>? <color>? [, …]*;

Values

#

Values in practice

#

none

An element without a shadow.
.demo { box-shadow: none; }

0 10px 30px rgba(0,0,0,.6)

A soft shadow under the element, like a raised card.
.demo { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); }

0 0 0 3px #a78bfa

A shadow with no blur and a spread acts like a border.
.demo { box-shadow: 0 0 0 3px #a78bfa; }

inset 0 4px 12px rgba(0,0,0,.8)

An inner shadow, the element looks recessed.
.demo { box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.8); }

0 0 24px #7c3aed

A coloured glow around the element.
.demo { box-shadow: 0 0 24px #7c3aed; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Layered shadows look more natural than one strong shadow. Combine a small one and a large, soft one.
  • On a dark background a shadow is barely visible. A lighter card surface or a subtle glow works better.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.