CSSApril 2026 ยท 6 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
โšก Key Takeaways
  • Add shadows to any element with CSS box-shadow.
  • Covers box-shadow syntax.
  • Covers layered shadows for realism.
  • Covers colored glow effects.
  • Covers performance 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
Stick to animating transform and opacity for smooth 60fps performance. These properties are handled by the GPU compositor and skip expensive layout recalculations.

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:

โš  Warning
Avoid animating width, height, top, or left. These trigger layout recalculations on every frame and can drop performance below 60fps.

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.