Developer Tools

CSS Box-Shadow: A Practical Guide With 15 Examples

Every box-shadow parameter decoded: offsets, blur, spread, inset and color. Plus layered shadows, glow effects and the performance habits that keep paint cheap.

4 min read·Updated 2026-04-19

The CSS box-shadow property is the Swiss Army knife of depth. A one-line declaration can lift a card, make a button glow, or press an element into the page — no image files, no gradients, just a painter algorithm. It is also easy to misuse: a shadow with the wrong spread or an opaque black color looks like a smudge. This guide decodes every parameter, shows production-ready patterns, and explains the performance habits that keep your compositing cheap.

The full syntax

The long form reads offset-x offset-y blur spread color, optionally starting with inset:

box-shadow: 2px 4px 8px 0 rgba(0, 0, 0, 0.2);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);

Each parameter controls one axis of the effect, and they compose into every effect you have ever admired.

What each value actually does

ValueMeaning
offset-xHorizontal shift; negative moves the shadow left
offset-yVertical shift; negative moves the shadow up
blur0 gives a hard edge; larger values soften and expand the edge
spreadPositive expands the shadow footprint; negative shrinks it
colorAny CSS color — including alpha via rgba() or hsl()
insetSamples inside the border, making the element look pressed in

Reading a real declaration

The classic "lifted card" is box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.35);. The -10px spread pulls the shadow footprint inward so the top edge of the glow stays close to the card while the bottom floats, which reads as elevation rather than a halo. Keep that pattern in mind: the combination of a small offset plus a negative spread is what separates a floating card from a neon smudge.

Fifteen ready-to-copy patterns

  • Subtle card: 0 1px 3px rgba(0,0,0,0.12)
  • Standard card: 0 4px 12px rgba(0,0,0,0.12)
  • Lifted card: 0 10px 30px -10px rgba(0,0,0,0.35)
  • Floating action button: 0 8px 20px rgba(0,0,0,0.18)
  • Soft blue glow: 0 0 20px 2px rgba(59,130,246,0.5)
  • Pressed button: inset 0 2px 4px rgba(0,0,0,0.25)
  • Nav bar depth: 0 1px 4px rgba(0,0,0,0.15)
  • Modal backdrop shadow: 0 24px 64px rgba(0,0,0,0.24)
  • Tooltip cling: 0 2px 8px rgba(0,0,0,0.2)
  • Image ring: 0 0 0 4px rgba(255,255,255,1), 0 6px 16px rgba(0,0,0,0.25)
  • Neumorphism light: inset 2px 2px 6px rgba(255,255,255,0.8), inset -2px -2px 6px rgba(0,0,0,0.08)
  • Header underline: 0 4px 8px -4px rgba(0,0,0,0.25)
  • Notification pop: 0 2px 12px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05)
  • Text-shadow-free depth: 0 1px 2px rgba(0,0,0,0.4)
  • Deep ambient + contact pair: 0 2px 4px rgba(0,0,0,0.12), 0 12px 28px rgba(0,0,0,0.16)

Layering two shadows for realism

Real objects cast two shadows: a tight, dark contact shadow and a wide, soft ambient one. You get both in a single declaration by comma-separating values. This is the pattern behind the last example above and the core trick of believable elevation. A layered effect like 0 1px 2px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.12) reads dramatically more natural than one large blur, and it costs no extra markup.

Matching shadows to your color system

A shadow's realism comes from its color and alpha more than its size. Prefer tinted shadows: use the Color Converter to turn your brand hex into an equivalent rgba() value, set alpha between 0.1 and 0.4, and bias the RGB channels toward the ambient light. Opaque black blurs (rgba(0,0,0,1)) almost always look wrong. When you build a layered card or a glowing button, coordinate the shadow with the surface — a Box Shadow Generator iteration makes offset, blur, spread and color tuning immediate, and the Gradient Generator helps you pair the surface color so the shadow direction stays consistent.

Performance notes you will feel

  • Do not animate box-shadow. Blur values trigger a repaint every frame, which drops frames on mobile. Prefer animating transform or opacity and keeping the shadow static.
  • Large blurs are expensive to composite. A 100px blur over hundreds of elements can dominate paint time; batch effects onto a few containers instead of every item.
  • Layers are free. Well, cheap — the cost is in blur surface area, so a tight plus soft pair usually costs less than one huge radius.

Frequently asked questions

What does the spread value do in simple terms? It scales the shadow's footprint without moving it. Positive spread enlarges the area the shadow covers (useful for focus rings), negative spread shrinks it so the shadow hugs the element's edge instead of forming a floating halo.

Can a box-shadow appear on only one side of an element? Not directly — offset the shadow and use a negative spread to hide the opposite side: 0 6px 12px -6px rgba(0,0,0,0.25) shows shadow mostly below, and 0 -6px 12px -6px shows it mostly above. It is an approximation, but a good one.

Do box-shadows affect layout? No. Shadows never take layout space; they paint over or under neighboring content. Reserve the whitespace in the layout yourself when a glow needs breathing room.

Tools used in this guide

Related guides