CSS Box Shadow: The Complete Guide with Examples

Master the box-shadow property — from basic syntax to layered effects that add depth and realism to your designs.

CSS & Design 2026-04-09 By Risetop Team 11 min read

Shadows are one of the most effective ways to add depth and hierarchy to a web interface. A well-crafted shadow can make a button feel clickable, a card feel elevated, and a modal feel like it's floating above the page. But the difference between a shadow that enhances your design and one that makes it look cheap is subtle — and it comes down to understanding the box-shadow property inside and out.

This guide covers every aspect of CSS box shadows: the full syntax, common patterns you'll use in real projects, advanced techniques like layered shadows, and performance considerations. Whether you're writing shadows by hand or using a box shadow generator, understanding the fundamentals will make your work dramatically better.

Box Shadow Syntax

The box-shadow property accepts up to six values. Here's the full breakdown:

box-shadow: [inset] [horizontal] [vertical] [blur] [spread] [color]; /* Example with all values */ box-shadow: inset 5px 5px 15px 5px rgba(0, 0, 0, 0.3);
💡 Key Insight: The blur and spread values behave differently than you might expect. Blur makes the shadow softer but doesn't change its base size. Spread actually changes the shadow's dimensions — positive spread makes it bigger than the element, negative makes it smaller.

Common Box Shadow Patterns

1. Subtle Elevation (Cards)

The most common use case. A light, soft shadow that suggests the element is slightly raised from the background.

/* Subtle card shadow */ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); /* Slightly more pronounced */ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);

The key here is using a very low opacity (0.05–0.15) and a moderate blur. The shadow should be barely noticeable — it should suggest depth without drawing attention to itself.

2. Material Design Elevation

Google's Material Design system defines specific shadow levels (1-5) for different elevation states. Each level increases the shadow's spread and darkness.

/* Level 1 — Cards, text fields */ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); /* Level 3 — FABs, dialogs */ box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23); /* Level 5 — Modals, navigation drawers */ box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);

3. Hard / Sharp Shadow (Neubrutalism)

A design trend that uses zero blur for a bold, graphic look. Popular in modern web design with high-contrast color schemes.

/* Neubrutalism-style hard shadow */ box-shadow: 8px 8px 0 #000; /* Colored hard shadow */ box-shadow: 6px 6px 0 #ff6b6b;

4. Inner Shadow (Inset)

Inset shadows create a "pressed in" effect, making an element look recessed or indented. Great for input fields and toggle states.

/* Recessed input field */ box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1); /* Inset top highlight (glass effect) */ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);

5. Glow Effect

Using a colored shadow with a large blur radius creates a glow. Perfect for focus states, active buttons, and dark-themed interfaces.

/* Blue glow — focus state */ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5); /* Neon glow effect */ box-shadow: 0 0 20px rgba(168, 85, 247, 0.6), 0 0 60px rgba(168, 85, 247, 0.3);

Layered Shadows: The Secret to Realistic Depth

A single shadow rarely looks realistic. In the real world, objects cast shadows from multiple light sources and onto multiple surfaces. You can simulate this by stacking multiple box-shadow values separated by commas.

/* Realistic floating card */ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07), /* Tight, dark shadow close to element */ 0 4px 8px rgba(0, 0, 0, 0.06), /* Medium spread */ 0 16px 32px rgba(0, 0, 0, 0.06); /* Broad, soft ambient shadow */

The technique is to combine a tight, relatively dark shadow (simulating the main light source) with a broader, lighter shadow (simulating ambient light). This creates a much more natural look than a single shadow with a large blur.

Hover State Enhancement

Adding or intensifying a shadow on hover is one of the most effective ways to communicate interactivity. It feels intuitive because it mimics the real-world behavior of picking something up.

.card { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); transition: box-shadow 0.3s ease; } .card:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 12px 24px rgba(0, 0, 0, 0.08); }

Box Shadow vs. Drop Shadow Filter

CSS offers two ways to create shadows: the box-shadow property and the filter: drop-shadow() function. They behave differently:

/* Box shadow on a circle — works great */ .box-shadow-circle { border-radius: 50%; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); } /* Drop shadow follows the actual shape */ .drop-shadow-shape { filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.2)); }

Use box-shadow for standard elements (cards, buttons, inputs). Use drop-shadow for non-rectangular elements (SVGs, clipped shapes, transparent PNGs).

Performance Considerations

Box shadows are rendered by the browser's compositor and can impact performance if misused:

💡 Performance Trick: Instead of animating box-shadow, use a ::after pseudo-element with the shadow and animate its opacity. This uses the GPU compositor and is significantly smoother.

Best Practices

Using a Box Shadow Generator

While understanding the syntax is essential, a CSS box shadow generator dramatically speeds up your workflow. You can visually adjust offsets, blur, spread, and color in real time, layer multiple shadows, and copy the resulting CSS with a single click. It's especially useful for fine-tuning the subtle differences between shadow levels in a design system.

Conclusion

Box shadows are a small detail that makes a huge difference in perceived quality. The difference between a flat, lifeless interface and one that feels polished often comes down to well-crafted shadows. Master the syntax, understand how to layer shadows for realism, use the right shadow for each context (elevation, inset, glow), and keep performance in mind. With practice — and a good box shadow generator to speed things up — you'll develop an instinct for shadows that make your designs feel professional and refined.

🌑 Design Your Perfect Shadow

Try our free Box Shadow Generator — layer multiple shadows, preview in real time, and copy production-ready CSS.

Open Box Shadow Generator →