CSS box-shadow Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Visual Effects

What You’ll Learn

The box-shadow property adds shadow effects around elements. You can control offset, blur, spread, color, and even stack multiple shadows to create depth, layering, and polished UI components like cards and buttons.

01

Shadow Basics

Add depth to any box.

02

Syntax

Offset, blur, spread, color.

03

Blur vs Spread

Soften or resize shadows.

04

inset

Inner shadow effects.

05

Multiple Shadows

Layer with commas.

06

UI Patterns

Cards, buttons, modals.

Definition and Usage

The box-shadow CSS property lets you attach one or more drop shadows to an element’s box. You can create multiple shadows separated by commas, and each shadow supports horizontal offset, vertical offset, blur radius, spread radius, color, and the optional inset keyword.

This property is versatile and widely used in modern web design. It adds depth and dimension to cards, buttons, navigation bars, and modals — helping users understand what is clickable and what sits above other content.

💡
Beginner Tip

Start with a simple shadow like 0 4px 8px rgba(0, 0, 0, 0.15). Adjust the vertical offset and blur until the element feels naturally elevated from the page.

📝 Syntax

The syntax for box-shadow includes several parameters, but not all are required. The most basic usage only needs horizontal and vertical offsets:

syntax.css
selector {
  box-shadow: h-offset v-offset blur-radius spread-radius color;
}

Basic Example

box-shadow.css
.box {
  box-shadow: 10px 10px 5px gray;
}

Syntax Rules

  • The initial value is none — no shadow until you set one.
  • h-offset and v-offset are required lengths (can be negative).
  • blur-radius and spread-radius are optional length values.
  • color is optional; browsers use a default shadow color if omitted.
  • Add inset at the start to draw the shadow inside the element.
  • Separate multiple shadows with commas — first listed shadow appears on top.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toAll elements
InheritedNo
AnimatableYes (when using compatible values)
Common useCards, buttons, dropdowns, and elevated panels

💎 Property Values

Each part of a box-shadow declaration controls a different aspect of the shadow appearance.

ValueExampleMeaning
h-offset10pxHorizontal shadow position. Positive moves right; negative moves left.
v-offset10pxVertical shadow position. Positive moves down; negative moves up.
blur-radius5pxSoftens shadow edges. Larger values create a more diffused shadow.
spread-radius2pxExpands or shrinks the shadow before blurring. Optional.
colorgray or rgba(0,0,0,0.2)Shadow color. Semi-transparent colors look more natural.
insetinset 0 2px 4px #000Draws the shadow inside the element as an inner shadow.
h-offset v-offset blur spread color inset

Blur vs. Spread

Beginners often confuse blur and spread because both change the shadow size. Here is the difference:

  • Blur-radius — Fades the shadow edges. A blur of 0 gives a sharp shadow; higher values make it softer and wider.
  • Spread-radius — Grows or shrinks the shadow uniformly before blurring. Positive spread makes the shadow bigger; negative spread pulls it inward.

For a natural card elevation, use a small vertical offset, moderate blur, and little or no spread — for example: 0 4px 12px rgba(0, 0, 0, 0.12).

👀 Live Preview

This box uses the reference example shadow: 10px 10px 5px gray.

Examples Gallery

Try basic shadows, soft card elevation, inset inner shadows, and layered multiple shadows.

🖼 Basic Shadows

Start with offset, blur, and color — the same pattern from the reference example.

Example 1 — Simple Box Shadow

Add a straightforward shadow to a box with horizontal offset, vertical offset, blur, and color.

basic-shadow.html
<style>
  .box {
    width: 200px;
    height: 200px;
    background-color: lightblue;
    box-shadow: 10px 10px 5px gray;
  }
</style>

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

How It Works

The shadow sits 10px to the right and 10px below the box, with a 5px blur and gray color. This creates a classic offset drop shadow.

📱 UI Components

Modern interfaces use soft, semi-transparent shadows rather than harsh gray offsets.

Example 2 — Soft Card Elevation

Create a polished card shadow with vertical offset and rgba color for a natural depth effect.

card-shadow.html
<style>
  .card {
    padding: 1.25rem;
    border-radius: 0.75rem;
    background: #fff;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  }
</style>

<article class="card">
  <h3>Card Title</h3>
  <p>Elevated with a soft shadow.</p>
</article>
Try It Yourself

How It Works

A zero horizontal offset and small vertical offset make the card appear lifted straight off the page. The rgba color keeps the shadow subtle on light backgrounds.

Example 3 — Inset Inner Shadow

Use the inset keyword to draw a shadow inside the element — great for pressed buttons or sunken inputs.

inset-shadow.html
<style>
  .pressed {
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: 0.5rem;
    background: #e2e8f0;
    box-shadow: inset 0 2px 6px rgba(15, 23, 42, 0.25);
  }
</style>

<button class="pressed">Pressed</button>
Try It Yourself

How It Works

The inset keyword flips the shadow direction so it appears inside the box boundary, creating a recessed, pushed-in look.

🎨 Layered Effects

Stack multiple comma-separated shadows to build richer depth and glow effects.

Example 4 — Multiple Box Shadows

Combine two shadows — a soft ambient shadow plus a tighter contact shadow — for realistic elevation.

multiple-shadow.html
<style>
  .elevated {
    width: 10rem;
    height: 6rem;
    border-radius: 0.75rem;
    background: #fff;
    box-shadow:
      0 1px 2px rgba(15, 23, 42, 0.08),
      0 8px 24px rgba(15, 23, 42, 0.12);
  }
</style>

<div class="elevated"></div>
Try It Yourself

How It Works

The first shadow adds a tight edge definition; the second adds a wider ambient glow. Together they mimic how real objects cast both a contact shadow and a softer outer shadow.

🧠 How box-shadow Works

1

You define shadow values

Set offset, blur, spread, color, and optionally inset on the element’s box.

CSS rule
2

The browser clones the box shape

It creates a shadow layer matching the element’s border box, including border-radius.

Shape matching
3

Offset, blur, and spread are applied

The shadow is moved, softened, and sized according to your values, then painted behind (or inside) the element.

Rendering
=

Depth and hierarchy

The element appears elevated, recessed, or highlighted — helping users scan and interact with your UI.

Universal Browser Support

The box-shadow property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is a standard CSS feature with excellent compatibility.

Baseline · All browsers

Reliable shadows on every platform

Chrome, Firefox, Safari, Edge, and Opera all support box-shadow consistently, including inset and multiple shadows.

98% Modern browser support
Google Chrome 10+ · Desktop & Mobile
Full support
Mozilla Firefox 4+ · Desktop & Mobile
Full support
Apple Safari 5.1+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 10.5+ · Modern versions
Full support
box-shadow property 98% supported

Bottom line: Use box-shadow freely in any project. It is one of the most dependable CSS visual effects available.

Conclusion

The box-shadow property is a powerful tool for adding depth and dimension to web elements. By experimenting with offsets, blur, spread, color, and inset, you can create a variety of shadow effects to enhance the visual appeal of your projects.

Use shadows to highlight important sections, create a sense of layering, or add a touch of elegance to cards, buttons, and modals. Start simple, then layer multiple shadows as your designs grow more polished.

💡 Best Practices

✅ Do

  • Use semi-transparent rgba() colors for natural-looking shadows
  • Prefer small vertical offsets for card elevation (0 4px ...)
  • Match shadow direction to your light source consistently
  • Use multiple shadows for richer, more realistic depth
  • Test shadows on both light and dark backgrounds

❌ Don’t

  • Use heavy black shadows on every element — it looks dated
  • Stack so many shadows that performance or clarity suffers
  • Rely on shadow alone to show focus — pair with outline or border
  • Forget that large spread values can look unnatural
  • Skip checking contrast when text sits on shadowed backgrounds

Key Takeaways

Knowledge Unlocked

Five things to remember about box-shadow

Use these points when adding depth to your next layout.

5
Core concepts
📏 02

Offset + Blur

Position and soften.

Syntax
📦 03

inset

Inner shadow effect.

Keyword
🔁 04

Multiple

Comma-separated list.

Layering
05

Universal

Works everywhere.

Support

❓ Frequently Asked Questions

box-shadow adds one or more shadows around an element's box. You control the shadow's position, softness, size, and color to create depth and visual hierarchy.
The initial value is none, which means no shadow is drawn until you set the property.
Blur-radius softens the shadow edges. Spread-radius makes the shadow larger or smaller before blurring — positive spread expands it, negative spread shrinks it.
The inset keyword draws the shadow inside the element instead of outside, creating an inner shadow or pressed-in effect.
Yes. Separate shadow definitions with commas. The first shadow in the list is painted on top. Multiple shadows are useful for layered card and button effects.

Practice in the Live Editor

Open the HTML editor, apply box-shadow, and preview depth effects instantly.

HTML Editor →

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.

5 people found this page helpful