CSS Portal

CSS box-shadow Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The box-shadow property is used to paint one or more shadows around an element’s frame, creating depth and separation from the page background. Unlike borders, shadows do not change layout or the element’s box dimensions; they are purely visual and are composited on top of or beneath the element’s background. You can layer multiple shadows to build subtle depth or dramatic emphasis, and shadows may be applied so they appear to emanate from outside the element or to appear contained within it, resulting in different visual effects.

Shadows interact with an element’s rounded corners and background filling: a clipped corner will produce a shadow that follows the curved edge, so combining border-radius with shadows is a common way to create soft, card-like surfaces. Because shadows are painted relative to an element’s box, they also work together with the element’s background to define perceived depth; a semi-transparent background color plus a gentle shadow can convey elevation, while a strong shadow against a light background gives a floating appearance. When elements are transformed (rotated, scaled, or translated), their shadows are transformed along with them, so consider the visual relationship between an element and its shadow when using transform.

Rendering and performance are important considerations when using shadows extensively. Complex or large shadows can increase paint and compositing work, especially when many elements or frequent animations are involved; in such cases it’s common to use a compositing hint like will-change or to render a shadow via a rasterized asset or pseudo-element to reduce repeated repaints. An alternative for some use cases is to use image-based or filtered effects - for instance the CSS drop-shadow via filter - which can sometimes be cheaper or offer different blending characteristics than native box shadows.

From a practical design standpoint, subtlety usually works best: mild, low-contrast shadows provide separation without overpowering content, while larger, higher-contrast shadows should be used sparingly for emphasis. Shadows should not be relied on as the only indicator for interactive focus or state; pair them with clear focus outlines or other cues such as color changes and borders - for focus outlines consider outline - and be mindful of stacking contexts and layering when overlapping elements (which is controlled in part by z-index). Finally, consider accessibility and color contrast: very subtle shadows may be invisible to some users or on certain displays, so test designs across backgrounds and devices.

Definition

Initial value
none
Applies to
All elements
Inherited
No
Computed value
Any <length> made absolute; any specified color computed; otherwise as specified
Animatable
Yes
JavaScript syntax
object.style.boxShadow

Interactive Demo

Example of the box shadow property.

Syntax

box-shadow: none | <shadow> [ , <shadow> ]* 

Values

<shadow> = inset? && <length>{2,4} && <color>?
  • 1st <length>Specifies the horizontal offset of the shadow. A positive value draws a shadow that is offset to the right of the box, a negative length to the left.
  • 2nd <length>Specifies the vertical offset of the shadow. A positive value offsets the shadow down, a negative one up.
  • 3rd <length>Specifies the blur radius. Negative values are not allowed. If the blur value is zero, the shadow's edge is sharp. Otherwise, the larger the value, the more the shadow's edge is blurred.
  • 4th <length>Specifies the spread distance. Positive values cause the shadow to expand in all directions by the specified radius. Negative values cause the shadow to contract.
  • <color>Specifies the color of the shadow. If the color is absent, the used color is taken from the 'color' property.
  • insetIf present, the 'inset' keyword changes the drop shadow from an outer box-shadow (one that shadows the box onto the canvas, as if it were lifted above the canvas) to an inner box-shadow (one that shadows the canvas onto the box, as if the box were cut out of the canvas and shifted behindit).

Example

<!-- Box-shadow examples -->
<div class="demo">
<h1>box-shadow examples</h1>
<div class="row">
<div class="box box--soft">Soft shadow</div>
<div class="box box--deep">Deep shadow</div>
<div class="box box--glow">Colored glow</div>
</div>
</div>
/* Basic page styles */
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f3f6f9;
    color: #222;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.demo {
    text-align: center;
}

.row {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    margin-top: 1rem;
}

.box {
    width: 180px;
    height: 120px;
    background: #ffffff;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    font-weight: 600;
    transition: box-shadow 200ms ease, transform 200ms ease;
}

/* Different box-shadow examples */
.box--soft {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.box--deep {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.20);
}

.box--glow {
    box-shadow: 0 8px 24px rgba(0, 150, 255, 0.18), 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

/* Hover to emphasize the shadow */
.box:hover {
    transform: translateY(-6px);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

Browser Support

The following information will show you the current browser support for the CSS box-shadow property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!