Box Shadow Generator

Create realistic shadow effects visually

Configuration
Preview Colors
Preview
box-shadow: 5px 5px 15px 0px rgba(0,0,0,0.2);

The Complete Guide to CSS Box-Shadow: Adding Depth to UI

Introduction: From Flat to Material

In the early days of the web, everything was 2D. Then Apple introduced skeuomorphism (leather textures, fake stitching). Then we swung back to ultra-flat design. Today, we live in the era of Material Design and Neumorphism, where depth is key. The primary tool for creating depth in CSS is the box-shadow property. It allows elements to "float" above the page, providing visual cues about hierarchy and interactivity.

Anatomy of a Shadow

The syntax box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75); looks scary, but it breaks down simply:

  • H-Offset (10px): Horizontal position. Positive moves right, negative moves left.
  • V-Offset (10px): Vertical position. Positive moves down (light source from top), negative moves up.
  • Blur Radius (5px): How sharp is the shadow? 0 is a hard edge. Higher numbers make it softer and more diffuse.
  • Spread Radius (0px): How big is the shadow? Positive values expand the shadow larger than the element. Negative values shrink it (useful for subtle floating effects).
  • Color: Usually black with opacity (`rgba(0,0,0,0.5)`). Colored shadows (e.g., a blue button casting a blue glow) are a modern trend.

Modern Shadow Styles

1. The "Card" shadow

Used by LinkedIn, Facebook, and Twitter cards. It's subtle. Low opacity (10-15%), large blur (20px), and small offset.

2. Neumorphism (Soft UI)

This trend mimics extruded plastic. It uses TWO shadows: a dark shadow on the bottom-right and a light (white) shadow on the top-left. This creates a realistic 3D highlight/shadow effect.

3. The "Glow"

Used on call-to-action buttons. It uses the button's own color as the shadow color, often with high blur and 50% opacity, making the button feel radioactive or neon.

Global Light Source

A key principle in design is consistency. If your buttons have a shadow casting down-right (h: 5px, v: 5px), your cards shouldn't have a shadow casting up-left. Imagine a single "Global Light Source" (like the sun) in the top-left corner of your screen. All shadows should fall away from that light. Inconsistent shadows make a UI feel "off" or chaotic to the user's subconscious.

Performance Notes

Box shadows are relatively expensive for the browser to paint. Shadows with large blur radii cover many pixels. Animating `box-shadow` (e.g., on hover) can cause "jank" (stuttering) on low-end devices because it forces the browser to re-paint the area on every frame. Use sparingly!

The `will-change` Hack

If you must animate a large shadow, adding `will-change: box-shadow` to the CSS tells the browser to promote that element to its own layer, potentially using the GPU to render the change smoother. But use this with caution, as too many layers can consume memory.

Layering Shadows

Did you know you can have multiple shadows? Just separate them with a comma:

box-shadow: 3px 3px 5px rgba(0,0,0,0.1), -3px -3px 5px rgba(255,255,255,0.5);

Check "Inset Shadow" in our tool to create inner depth (like a pressed button or an input field).

Frequently Asked Questions (FAQ)

Why is my shadow clipped?

If the parent element has `overflow: hidden`, any shadow extending outside that parent will be cut off. Increase the parent's padding or remove the overflow rule.

How do I make a shadow only on one side?

Use a negative "Spread" radius equal to the blur. Or simply position the offset so perfectly that the shadow hides behind the element on the other side.

What is an Inset properties?

It draws the shadow inside the box border. This is used for creating "sunken" effects, like text inputs, pressed buttons, or wells.

Does box-shadow include the border?

Yes. The shadow starts from the outer edge of the border. If you have `border-radius`, the shadow will curve to match it perfectly.

Can I animate box-shadow?

Yes, `transition: box-shadow 0.3s ease` works great. It's perfect for hover effects on cards and buttons. Just try to avoid animating the "Blur" radius too wildly as it is computationally expensive.

Does it affect layout?

No. Shadows do not take up space in the document flow. They can overlap other elements without pushing them away. Make sure to add `margin` if you don't want overlap.

What is the "Spread" value for?

Standard CSS shadows are the same size as the element. "Spread" makes the shadow physically larger (positive) or smaller (negative) than the element itself.