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)"
Example
#.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);
}<div style="padding: 24px;">
<div style="padding: 16px; border-radius: 14px; background: #18181b; transition: box-shadow .2s; box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px -8px rgba(0,0,0,.6);">Hover to see the effect in your own project</div>
</div>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
#box-shadow: none | inset? <offset-x> <offset-y> <blur>? <spread>? <color>? [, …]*;Values
#- An element without a shadow.
- A soft shadow under the element, like a raised card.
outline
A shadow with no blur and a spread acts like a border.inset 0 4px 12px rgba(0,0,0,.8)
inset
An inner shadow, the element looks recessed.glow
A coloured glow around the element.
Values in practice
#none
.demo { box-shadow: none; }0 10px 30px rgba(0,0,0,.6)
.demo { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); }0 0 0 3px #a78bfa
.demo { box-shadow: 0 0 0 3px #a78bfa; }inset 0 4px 12px rgba(0,0,0,.8)
.demo { box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.8); }0 0 24px #7c3aed
.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.