CSS box-shadow
The box-shadow property is one of the properties introduced in CSS3 to enable developers with the ability to add shadow effects to HTML elements.
The CSS box-shadow property is used for attaching one or more drop shadows to an HTML element. You can create drop shadows on any HTML element. You can even give them that "blurred" effect (also known as "Gaussian blur").
You can specify which color the drop shadow should be as well as it's offset from its box (i.e. how far it should drop down/away from the HTML element that you apply the drop shadow to).
The box-shadow property accepts a comma-separated list of shadows, each specified by 2-4 length values, an optional color, and an optional inset keyword. Omitted lengths are 0; omitted colors are taken from the color property.
Syntax
Where:
See below for an explanation.
Possible Values
Here's an explanation of these values:
none- This keyword specifies that no drop shadow will be added to the element. If you use this keyword, there's no need to add the other values.
- <length>{2,4}
-
This can be either two values, three values, or four, as indicated below:
- <horizontal-offset> (required)
-
Determines the horizontal offset of the drop shadow. It is a
<length>value. For example,10pxor1em. Negative values are allowed. If a negative value is provided, the offset will result in the drop shadow being drawn to the left of the box. If it is a positive value, it will be drawn to the right. - <vertical-offset> (required)
-
Determines the vertical offset of the drop shadow. It is a
<length>value. For example,10pxor1em. Negative values are allowed. If a negative value is provided, the offset will result in the drop shadow being drawn above the box. If it is a positive value, it will be drawn below. - <blur> (optional)
-
Determines the Gaussian blur effect (if any). It is a
<length>value. If the value is zero (i.e.0), the edge of the shadow will be sharp. The higher the value, the more blurred the shadow will become. Negative values are not allowed for a Gaussian blur. - <spread_distance> (optional)
-
Determines the size of the drop shadow. It is a
<length>value. Adding a positive value here will increase the size of the drop shadow - it will expand in all directions. A negative value will decrease the size (it will contract).
- <color>? (optional)
-
Determines the color of the drop shadow. It can be any valid
<color>value. For example,steelblue,#FF4500orrgba(0,0,0,0.3)are all valid colors. If this value isn't provided, the value will be taken from thecolorproperty. inset- This (optional) keyword specifies that the drop shadow will be added to the inside of the element, making it an "inner shadow". This can give the element the appearance being "cut out" of the canvas/page (as opposed to an "outer shadow" in which the element appears to be hovering above the page). If the
insetkeyword is omitted, the drop shadow will be an "outer shadow".
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
initial- Represents the value specified as the property's initial value.
inherit- Represents the computed value of the property on the element's parent.
unset- This value acts as either
inheritorinitial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
Basic Property Information
- Initial Value
none- Applies To
- All elements
- Inherited?
- No
- Media
- Visual
- Animatable
- As shadow list. (see example)
Example Code
Basic CSS
Working Example within an HTML Document
CSS Specifications
- The
box-shadowproperty is defined in CSS Backgrounds and Borders Module Level 3 (W3C Candidate Recommendation Snapshot)
Browser Support
Browser support for CSS properties can vary, particularly for newer or experimental features. Check current browser compatibility before using a property in production, especially when supporting older browsers.
The following table provided by Caniuse.com shows the level of browser support for this feature.
Initial Value
CSS properties have an initial value that applies when the property has not been explicitly set. The initial value is different from the value inherited from a parent element and may vary between properties.
Inheritance
Some CSS properties inherit their computed value from their parent element by default, while others do not. The inherit, initial, unset, and revert keywords can also be used to control how a property gets its value.
Vendor Prefixes
Most modern CSS properties use the standard, unprefixed syntax. Vendor-prefixed properties such as -webkit- are mainly relevant to older browser versions or specific features and should only be used when required by your browser support targets.