CSSMar 16, 2026 Β· 2 min read

How to Create a CSS Box Shadow (With Examples)

The CSS box-shadow property adds depth, elevation, and visual polish to elements. From subtle card shadows to neon glows, it's one of the most versatile visual properties in CSS. The syntax takes up to six values β€” once you understand the order, you can create any shadow effect.

πŸŒ‘
Try the Shadow Generator
Free, no signup
β†’
DG
Derek Giordano
Designer & Developer
In this guide
01Box-Shadow Syntax02Layered Shadows for Realism03Colored Glow Effects04Performance Tips

Box-Shadow Syntax

The box-shadow property follows this order:

box-shadow: [inset] offset-x offset-y blur-radius spread-radius color;
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15);

Offset-x moves the shadow horizontally (positive = right). Offset-y moves it vertically (positive = down). Blur-radius softens the edge (0 = sharp). Spread-radius expands or contracts the shadow area. Color should use rgba() for natural-looking semi-transparent shadows.

Layered Shadows for Realism

Single shadows look flat. Production-quality shadows use multiple layers that mimic how light scatters in the physical world:

πŸ’‘ Tip
Animating width, height, top or left makes the browser redo layout, and usually paint, on every frame. Google’s web.dev animation guide recommends keeping animations to transform and opacity where you can, so they stay on the compositing stage; check with the Performance panel in your browser’s dev tools.
box-shadow:
  0 1px 2px rgba(0, 0, 0, 0.07),
  0 2px 4px rgba(0, 0, 0, 0.07),
  0 4px 8px rgba(0, 0, 0, 0.07),
  0 8px 16px rgba(0, 0, 0, 0.07);

Each layer doubles the offset and blur while keeping opacity low. The result is dramatically more realistic than a single shadow with the same total darkness.

Colored Glow Effects

Zero-offset shadows with high blur create glow effects:

box-shadow: 0 0 20px rgba(0, 255, 209, 0.4);

Layer multiple glows for intensity:

box-shadow:
  0 0 10px rgba(0, 255, 209, 0.3),
  0 0 30px rgba(0, 255, 209, 0.2),
  0 0 60px rgba(0, 255, 209, 0.1);

This is popular for CTAs, featured cards, and dark-mode interfaces. Use the Shadow Generator to build and preview these effects visually.

Performance Tips

Avoid animating box-shadow directly β€” each frame triggers a repaint. Instead, create a pseudo-element with the target shadow and animate its opacity. The shadow is painted once, and opacity animation is GPU-accelerated:

.card::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.3s;
}
.card:hover::after { opacity: 1; }

Frequently Asked Questions

How do I add a shadow to a div in CSS?+
Use box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15). The values are horizontal offset, vertical offset, blur radius, and color. Adjust blur and opacity to control softness and intensity.
What is an inset box shadow?+
Adding the 'inset' keyword puts the shadow inside the element instead of outside. It creates a pressed or recessed effect, commonly used for input fields and pressed button states.
How do I create a neon glow effect?+
Use box-shadow with zero offset and high blur: box-shadow: 0 0 20px rgba(0, 255, 209, 0.4). Layer multiple shadows with increasing blur for a more intense glow.
Try it yourself

Use the Shadow Generator β€” free, no signup required.

⚑ Open Shadow Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.