Table of contents
- 1. Summary
- 2. Syntax
- 3. Values
- 4. Live examples
- 5. Browser compatibility
- 5.1. Notes
- 6. Specifications
« CSS « CSS Reference
Summary
The box-shadow CSS property accepts one or more shadow effects as a comma-separated list. It allows casting a drop shadow from the frame of almost any element. If a border-radius
is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The z-ordering of multiple box shadows is the same as multiple text shadows (the first specified shadow is on top).
- Initial value
:
none - Applies to: all elements
- Inherited : no
- Media:
visual - Computed value
: as specified (any
<length>made absolute; any<color>computed)
Syntax
box-shadow: none | <shadow> [,<shadow>]* where <shadow> is defined as: inset? && [ <offset-x> <offset-y> <blur-radius>? <spread-radius>? <color>? ]
Values
- inset (optional)
- If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content).
The presence of theinsetkeyword changes the shadow to one inside the frame (as if the content was depressed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content. - <offset-x> <offset-y> (required)
- This are two
<length>values to set the shadow offset.<offset-x>specifies the horizontal distance. Negative values place the shadow to the left of the element.<offset-y>specifies the vertical distance. Negative values place the shadow above the element. See<length>for possible units.
If both values are0, the shadow is placed behind the element (and may generate a blur effect if<blur-radius>and/or<spread-radius>is set). - <blur-radius> (optional)
- This is a third
<length>value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be0(the shadow's edge is sharp). - <spread-radius> (optional)
- This is a fourth
<length>value. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. If not specified, it will be0(the shadow will be the same size as the element). - <color> (optional)
- See
<color>values for possible keywords and notations.
If not specified, the color depends on the browser. In Gecko (Firefox), Presto (Opera) and Trident (Internet Explorer), the value of thecolorproperty is used. On the other hand, WebKit's shadow is transparent and therefore useless if<color>is omitted.
Live examples
-moz-box-shadow: 60px -16px teal;
-webkit-box-shadow: 60px -16px teal;
box-shadow: 60px -16px teal;
-moz-box-shadow: 10px 5px 5px black;
-webkit-box-shadow: 10px 5px 5px black;
box-shadow: 10px 5px 5px black;
-moz-box-shadow: 3px 3px red, -1em 0 0.4em olive;
-webkit-box-shadow: 3px 3px red, -1em 0 0.4em olive;
box-shadow: 3px 3px red, -1em 0 0.4em olive;
-moz-box-shadow: inset 5em 1em gold;
-webkit-box-shadow: inset 5em 1em gold;
box-shadow: inset 5em 1em gold;
-moz-box-shadow: 0 0 1em gold;
-webkit-box-shadow: 0 0 1em gold;
box-shadow: 0 0 1em gold;
-moz-box-shadow: inset 0 0 1em gold;
-webkit-box-shadow: inset 0 0 1em gold;
box-shadow: inset 0 0 1em gold;
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 10.0 1.0 -webkit | 4.0 (2.0)
3.5 (1.9.1) -moz | 9.0 (See note) | 10.5 | 5.1 (WebKit 534) 3.0 (WebKit 522) -webkit |
| Multiple shadows | 10.0 1.0 -webkit | 4.0 (2.0)
3.5 (1.9.1) -moz | 9.0 | 10.5 | 5.1 (WebKit 534) 3.0 (WebKit 522) -webkit |
inset keyword | 10.0 4.0 -webkit | 4.0 (2.0)
3.5 (1.9.1) -moz | 9.0 | 10.5 | 5.1 (WebKit 534) 5.0 (WebKit 533) -webkit |
| Spread radius | 10.0 4.0 -webkit | 4.0 (2.0)
3.5 (1.9.1) -moz | 9.0 | 10.5 | 5.1 (WebKit 534) 5.0 (WebKit 533) -webkit |
| Feature | iOS Safari | Opera Mini | Opera Mobile | Android Browser |
|---|---|---|---|---|
| Basic support | 5.0 | ? | ? | ? |
| Multiple shadows | 5.0 (Yes) -webkit | ? | ? | ? |
inset keyword | 5.0 (Yes) -webkit | ? | ? | ? |
| Spread radius | 5.0 (Yes) -webkit | ? | ? | ? |
Notes
- Since version 5.5, Internet Explorer supports Microsoft's DropShadow and Shadow Filter. You can use this proprietary extension to cast a drop shadow (though the syntax and the effect are different from CSS3).
- Shadows affect layout in older Gecko, Presto, and WebKit; e.g. if you cast an outer shadow to a box with a
widthof100%, you'll see a scrollbar. - Gecko 13 (Firefox 13) removed support for
-moz-box-shadow. Since then, only the unprefixed version is supported. - In order to get
box-shadowin IE9 or later, you need to setborder-collapsetoseparate. [1]
Specifications


Mozilla Developer Network