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.
Fundamentals
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.
Foundation
📝 Syntax
The syntax for box-shadow includes several parameters, but not all are required. The most basic usage only needs horizontal and vertical offsets:
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.
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.
Compatibility
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 Chrome10+ · Desktop & Mobile
Full support
Mozilla Firefox4+ · Desktop & Mobile
Full support
Apple Safari5.1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera10.5+ · Modern versions
Full support
box-shadow property98% supported
Bottom line: Use box-shadow freely in any project. It is one of the most dependable CSS visual effects available.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about box-shadow
Use these points when adding depth to your next layout.
5
Core concepts
🖼01
Drop Shadows
Adds depth to boxes.
Purpose
📏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.