CSS Reference ยท Borders, Outlines and Shadows
The box-shadow property
Reference for the CSS box-shadow property: offsets, blur, spread, inset shadows and multiple layered shadows, with live examples, syntax and usage notes.
The box-shadow property draws one or more shadows around an element's box. Each shadow is described by an offset, an optional blur radius, an optional spread distance and a color. Adding the keyword inset draws the shadow inside the box instead of outside.
Shadows follow the element's rounded corners (border-radius), do not take up space in the layout, and never react to mouse clicks. You can list several shadows separated by commas to build soft, layered effects.
.card { box-shadow: 0 4px 12px rgb(0 0 0 / 0.15); }
Try it
Syntax
box-shadow: none | <shadow>#; /* <shadow> = inset? && <length>{2,4} && <color>? */ /* the lengths are: offset-x offset-y blur-radius spread-radius */
- Initial value:
none - Applies to: all elements
- Inherited: no
- Animatable: yes (shadows are interpolated; lists with the same number of shadows animate smoothly)
- Computed value:
none, or a list of shadows with lengths made absolute and colors computed
Values
| Value | Description |
|---|---|
offset-x |
Horizontal distance. Positive moves the shadow right, negative left. Required. |
offset-y |
Vertical distance. Positive moves the shadow down, negative up. Required. |
blur-radius |
Optional, non-negative. 0 gives a sharp edge; larger values make a softer, wider blur. |
spread-radius |
Optional. Positive grows the shadow in all directions; negative shrinks it. |
<color> |
Optional; defaults to currentcolor. Semi-transparent colors look most natural. |
inset |
Draws the shadow inside the border edge, above the background. |
none |
No shadow. |
Usage notes
- First shadow is on top. With several shadows, the first in the list is drawn nearest the viewer.
- Does not affect layout. The shadow can overlap neighbors and be clipped by an ancestor with
overflow: hidden. Leave room with margin or padding. - Spread-only rings.
box-shadow: 0 0 0 3px colormakes a ring that follows rounded corners. It is often used as a focus indicator, but it disappears in forced colors mode, so combine it with a transparentoutline. - Performance. Large blur radii on many elements are expensive to paint, and animating
box-shadowforces repaints. For a hover lift, fade the opacity of a pseudo-element that carries the shadow instead. - Use alpha, not gray.
rgb(0 0 0 / 0.15)blends with any background, while solid gray looks dirty on colored surfaces. - Text. For shadows on glyphs use
text-shadow; for the outline of an image with transparency usefilter: drop-shadow(), sincebox-shadowfollows the rectangular box.
Browser support
Supported in every browser.
Related
text-shadowoutlineborder-radiusfilterโ includingdrop-shadow()- Lesson: Box Shadows