CSS box-shadow Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The box-shadow property adds one or more shadows around an element’s frame. Each shadow uses X/Y offsets, optional blur and spread, a color, and an optional inset keyword.

The initial value is none. Shadows follow border-radius, do not change layout size, and can be stacked with commas. For text, use text-shadow. For a non-standard mirror effect, see box-reflect.

Standard-track.

Not deprecated and not experimental. Baseline widely available across modern browsers (IE 9+).

CSS Syntax

syntax.css
box-shadow: none | inset? && <length>{2,4} && <color>? | initial | inherit;

Lengths mean: offset-x, offset-y, then optional blur, then optional spread. List multiple shadows with commas.

Property Values

ValueDescriptionTry it
noneDefault. No shadowTry it
offset-x offset-yRequired lengths. Negative X goes left; negative Y goes upTry it
blur-radiusOptional. Softens the edge. Cannot be negativeTry it
spread-radiusOptional. Expands (+) or shrinks (-) the shadow before blurTry it
<color>Shadow color. If omitted, uses the element colorTry it
insetDraws the shadow inside the boxTry it
comma listMultiple shadows. First is painted on topTry it
initialResets to noneTry it
inheritTakes the parent valueTry it

How to Use box-shadow

Start with offsets, then soften with blur, then tune size and color.

  1. Set offset-x and offset-y (for example 4px 8px).
  2. Add blur for softness (for example 4px 8px 16px).
  3. Add spread if you need a larger or tighter shadow (fourth length).
  4. Pick a color, often with alpha such as rgb(0 0 0 / 0.2).
  5. Use inset for an inner shadow, or commas for layered shadows.
PieceRequired?Role
X / Y offsetYesWhere the shadow sits relative to the box
BlurOptionalSoft edge. 0 is a hard edge
SpreadOptionalGrows or shrinks the shadow shape
Color / insetOptionalPaint and inner vs outer placement

Live Preview

The card stays the same. Change only box-shadow and watch the depth.

Shadows do not change the box width or height. Leave space so they are not clipped.

Shadow

Card

box-shadow: soft drop

CSS Examples

Each snippet focuses on box-shadow. Use Try It Yourself for a live editor.

Example 1 — Simple Offset Shadow

Two lengths move the shadow. No blur means a hard edge.

CSS
<style>
  .box {
    box-shadow: 6px 6px 0 #1d4ed8;
  }
</style>

<div class="box">Card</div>
Try It Yourself

How It Works

  1. Set X and Y. 6px 6px shifts the shadow right and down.
  2. Blur is omitted. That is the same as blur 0 — a sharp edge.
  3. Color is last. Blue fills the shadow.
  4. Outside by default. Without inset, this is a drop shadow.

Example 2 — Soft Drop Shadow

A third length softens the shadow for a light card lift.

CSS
<style>
  .box {
    box-shadow: 4px 8px 16px rgb(15 23 42 / 0.2);
  }
</style>

<div class="box">Card</div>
Try It Yourself

How It Works

  1. Offsets first. 4px 8px place the shadow slightly down-right.
  2. Blur softens. 16px spreads the edge so it looks airy.
  3. Use alpha. rgb(... / 0.2) keeps the shadow gentle.
  4. No layout change. Width and height stay the same; only paint is added.

Example 3 — Inner Shadow

inset draws the shadow inside the box for a pressed look.

CSS
<style>
  .box {
    box-shadow: inset 0 2px 8px rgb(15 23 42 / 0.25);
  }
</style>

<div class="box">Card</div>
Try It Yourself

How It Works

  1. Add inset. The shadow paints inside the padding box.
  2. Small Y offset. 0 2px pushes the shade slightly downward.
  3. Blur softens the well. 8px keeps the edge smooth.
  4. Sits under content. Text and children stay readable above the inner shadow.

Edge Cases & Pitfalls

Shadows are paint only. Watch clipping, stacking, and contrast.

layout

Does not change box size

Shadows sit outside the box model. A parent with overflow: hidden can clip them even though width/height are unchanged.

radius

Follows border-radius

If the element has border-radius, the shadow corners match that curve.

stack

First shadow is on top

In a comma list, earlier shadows paint above later ones. Order matters for layered looks.

vs outline

Not a focus ring substitute alone

For keyboard focus, prefer a clear outline (or a deliberate focus style). Shadows alone can be easy to miss.

perf

Heavy stacks cost paint

Many large blurred shadows on busy pages can slow scrolling. Keep card shadows light when you can.

Browser Support

box-shadow is a browser style property. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

box-shadow

Chrome 10+, Firefox 4+, Safari 5.1+, Edge 12+, Opera 10.5+, Internet Explorer 9+. Safe for production without a prefix.

98% global support
Google Chrome 10+
Full support
Mozilla Firefox 4+
Full support
Apple Safari 5.1+
Full support
Microsoft Edge 12+
Full support
Opera 10.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 9+
Full support
box-shadow Universally supported in modern browsers

Bottom line: Unprefixed box-shadow is standard and widely supported. No vendor prefix is needed in current browsers.

Key Takeaways

  • Role: paint outer or inset shadows around a box.
  • Order: X, Y, blur, spread, color — plus optional inset.
  • Layers: comma-separate shadows; the first sits on top.
  • Layout: shadows do not add to width or height.

One line: box-shadow adds depth with offset, blur, spread, and color — outside or inset.

Frequently Asked Questions

It paints one or more shadows around an element's box using offset, blur, spread, color, and an optional inset keyword.
The initial value is none, so no shadow is drawn until you set one.
Blur softens the shadow edge. Spread grows or shrinks the shadow before blur — positive expands, negative contracts.
inset draws the shadow inside the element (a pressed-in look) instead of outside as a drop shadow.
Yes. Separate shadows with commas. The first shadow in the list is painted on top.
It is Baseline widely available: Chrome 10+, Firefox 4+, Safari 5.1+, Edge 12+, Opera 10.5+, Internet Explorer 9+. It is a browser style property, not a Node.js feature.

Next: box-sizing

Control whether padding and border are inside the width.

box-sizing tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful