CSS Box Shadow Guide

What Is CSS Box Shadow?

The CSS box-shadow property adds shadow effects around an element’s frame. Shadows create visual depth, simulate elevation, draw attention to interactive elements, and add polish to modern web designs. From subtle card elevations to dramatic glow effects, box shadows are one of the most versatile tools in CSS.

Unlike older techniques that required images for shadow effects, CSS box shadows are rendered natively by the browser. They are lightweight, scalable, and easy to customize without touching any graphic editing software.

Box Shadow Syntax

The full box-shadow syntax includes up to six values:

box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] <color>;

Basic Shadow Examples

Subtle card shadow (the most common use case):

box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

This creates a soft shadow below the element, simulating gentle elevation. The low opacity (0.1) keeps it subtle.

Medium elevation:

box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

A larger blur radius and slightly higher opacity create the impression of greater distance from the background.

Strong shadow for emphasis:

box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);

This works well for modal dialogs, dropdown menus, and elements that need to appear above the page content.

Layered Shadows for Realism

Real-world shadows are complex, with both a soft ambient component and a sharper directional component. Layering multiple box shadows creates more realistic depth:

box-shadow:
  0 1px 3px rgba(0, 0, 0, 0.12),
  0 1px 2px rgba(0, 0, 0, 0.24);

The first shadow provides a broad, soft ambient shadow. The second adds a tighter, more defined shadow closer to the element. Together, they simulate natural light behavior far better than a single shadow.

Material Design popularized this approach with its elevation system, where each elevation level uses a carefully crafted set of layered shadows. Many design systems now use similar multi-shadow approaches.

Inset Shadows

Adding the inset keyword creates shadows inside the element:

box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);

Inset shadows are useful for:

Creative Shadow Techniques

Beyond standard elevation shadows, box-shadow enables creative effects:

Glow effect: Using a bright color with a large blur radius creates a glowing halo:

box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);

Colored shadows matching the element: Instead of black or gray shadows, use a darker or more saturated version of the element’s background color. This creates a more natural, cohesive look.

Border-like effect: A shadow with zero blur and zero offset but a positive spread acts like an additional border that does not affect layout:

box-shadow: 0 0 0 3px #3b82f6;

This is commonly used for focus indicators because it follows the element’s border-radius and does not shift content.

Shadow on one side only: Using negative spread to eliminate the shadow from most sides:

box-shadow: 0 4px 6px -4px rgba(0, 0, 0, 0.3);

The negative spread shrinks the shadow, and combined with the y-offset, it appears only below the element.

Interactive Shadow Transitions

Changing shadows on hover or focus creates engaging interaction feedback:

.card {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

The card appears to lift toward the user on hover. The transition property ensures a smooth animation between shadow states. Keep transition durations short (150-300ms) for responsive-feeling interactions.

This technique also pairs well with CSS gradient backgrounds for visually rich cards and buttons.

Performance Considerations

Box shadows are generally performant, but keep these guidelines in mind:

Building Shadows Visually

While experienced designers can write box-shadow CSS from memory, fine-tuning multiple layered shadows with precise offsets, blur radii, and colors is much faster with a visual tool. A box shadow generator lets you adjust each parameter in real time and preview the result, then copy the CSS into your project.

Try our free CSS Box Shadow Generator — no signup required.

Explore all free tools on CalcHub

Browse Tools