How CSS Box Shadow Works: Offsets, Blur, Spread and Layers

Understand every value in the CSS box-shadow property, how layered and inset shadows work, and how to design realistic, accessible shadows that perform well.

Updated September 29, 2026 5 min read

Use the free Box Shadow GeneratorCreate layered CSS box shadows with a live preview

Shadows tell the eye what sits on top of what. A card that lifts slightly off the page, a dropdown that floats over content, a pressed button that looks sunk into its surface: each of these relies on box-shadow. Get it right and an interface feels calm and tactile. Get it wrong and every element looks smudged, or harsh, or as if it is hovering far above the screen.

This guide explains each value in the box-shadow property, how layering and inset shadows work, and the design choices that make shadows look natural. It also covers how to build one with a live preview and when to reach for alternatives.

The box-shadow syntax

A single shadow has up to six parts:

box-shadow: inset 0 10px 30px -5px rgba(0, 0, 0, 0.2);
/*          [inset] x  y    blur spread colour */
  • inset (optional) puts the shadow inside the element, as if it were pressed in.
  • Horizontal offset (x) moves the shadow right for positive values and left for negative ones.
  • Vertical offset (y) moves it down for positive values and up for negative ones.
  • Blur radius softens the edge. 0 gives a hard edge; larger values spread the fade over more pixels. It cannot be negative.
  • Spread radius grows or shrinks the shadow before it is blurred. A negative spread pulls the shadow in, which is useful for keeping it from peeking out at the sides.
  • Colour is usually black or a dark tint with transparency.

The shadow follows the element's border-radius, so rounded cards get rounded shadows automatically.

Blur versus spread

People often mix these up. Spread changes the size of the solid shadow shape; blur changes how soft its edge is. A shadow with 0 0 0 4px is a crisp 4-pixel outline, which is a handy trick for focus rings that do not affect layout. A shadow with 0 0 12px 0 is a soft glow the same size as the element.

Why layered shadows look more real

In the real world, an object casts a sharp, dark shadow close to it and a wider, fainter one further away. A single CSS shadow cannot do both. Stacking two or three shadows, separated by commas, gets much closer:

box-shadow:
  0 1px 2px rgba(0, 0, 0, 0.07),
  0 4px 8px rgba(0, 0, 0, 0.07),
  0 16px 32px rgba(0, 0, 0, 0.07);

The first shadow in the list is drawn on top. Keeping each layer's opacity low and doubling the offset and blur at each step produces a soft, natural lift.

Build a shadow with a live preview

The Box Shadow Generator lets you adjust each value with sliders and see the result instantly.

  1. Open the Box Shadow Generator. It starts with a soft single shadow.
  2. Under Shadow layers, click a layer to edit it. Add layer creates another shadow, the duplicate button copies the selected one, and the bin icon removes a layer.
  3. Adjust Horizontal offset (X), Vertical offset (Y), Blur radius, Spread radius and Opacity with the sliders.
  4. Pick a Shadow colour, and switch on Inset for an inner shadow.
  5. Try the Presets: Soft, Material, Layered, Hard, Glow, Inset and Neumorphic are good starting points to tweak.
  6. In Live preview, change the Box colour and Background to match your design, and use Box corner radius (preview only) to see how the shadow follows rounded corners. The radius is not added to the output.
  7. Copy the rule from CSS code. Reset returns to the starting shadow and default preview colours.

Previewing on your real background colour matters: a shadow that looks perfect on white can disappear on light grey.

Other ways to create shadows

Design tools

Figma and similar tools describe shadows with the same x, y, blur and spread values, and many export them as CSS. They are ideal if the design team already owns the shadow tokens; just check that blur values match, as some tools define blur slightly differently from CSS.

Browser developer tools

Chrome and Edge include a shadow editor in the Styles panel. Click the small icon beside a box-shadow value to drag the offset and adjust blur on the live page.

Design system tokens

If you use a framework such as Tailwind or Material, it already defines a scale of elevation shadows. Using those keeps shadows consistent across a product, which usually matters more than any single shadow being perfect.

Tips, pitfalls and performance

Pick one light source

Keep the direction of every shadow consistent, usually light from above, so positive y offsets and small or zero x offsets. Mixed directions make an interface feel subtly wrong.

Tint shadows on coloured backgrounds

Pure black at low opacity can look dirty on a coloured surface. A dark, desaturated version of the background colour looks more natural.

Shadows are not borders

Many users with low vision rely on high-contrast modes that remove shadows entirely. If a card's boundary matters, add a faint border as well, and never rely on a shadow alone to show that something is focused. In Windows high-contrast mode, for example, box shadows are typically not shown.

Performance

Static shadows are cheap. Animating box-shadow directly forces the browser to repaint on every frame, which can stutter on lower-end devices. A common technique is to put the larger shadow on a pseudo-element and animate its opacity instead.

Soft UI styles combine a light and a dark shadow on the same element; the neumorphism generator is built for that look. For shadows on text rather than boxes, text-shadow has similar syntax without spread or inset; the text shadow generator covers it. For shapes cut with clip-path or transparent PNGs, filter: drop-shadow() follows the visible shape instead of the rectangular box.

Shadows pair naturally with rounded corners and gradients. See the border radius generator for corner shapes and the CSS gradient generator for backgrounds.

Frequently asked questions

What is the difference between box-shadow and drop-shadow?

box-shadow draws around the element's rectangular box (following its border radius). filter: drop-shadow() follows the actual visible pixels, so it suits icons, transparent images and clipped shapes, but it has no spread or inset option.

How do I add a shadow on only one side?

Use an offset towards that side and a negative spread equal to the blur, for example 0 8px 6px -6px rgba(0,0,0,0.3) for a shadow only below.

Can I use more than one shadow?

Yes. Separate shadows with commas. The first one in the list is drawn on top, and you can mix inset and outer shadows on the same element.

Why is my shadow cut off?

A parent element with overflow: hidden clips anything outside its box, including shadows. Add padding to the parent or move the overflow rule.

Does box-shadow affect layout?

No. Shadows do not take up space or push other elements, which is why a spread-only shadow is a popular way to draw an outline without shifting content.

Try it now: Box Shadow Generator

Loading tool…