What Is a CSS Box-Shadow?
The box-shadow property paints one or more shadows around an element’s border box. It is the CSS workhorse for elevation — the visual cue that a card floats above the page, a modal sits above the app, or a button is pressable. Because it is pure CSS (no images, no gradients-on-edges hacks), it scales crisply on every display and animates cheaply with a transition.
A declaration looks like box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15); — five values: x-offset, y-offset, blur radius, spread, and color. Order matters: x before y, blur before spread, and blur can only be zero or positive while spread can go negative.
The Five Values, One by One
- x-offset — horizontal shift. Positive moves the shadow right, negative left. 0 keeps it centered under the element.
- y-offset — vertical shift. Positive moves it down. The single most expressive value: 4px reads as “hovering”, 20px as “floating”.
- blur radius — how soft the edge is. 0 gives a hard, poster-like edge; 25+ gives a diffuse cloud. The shadow extends this far beyond the offset edge.
- spread — grows (+) or shrinks (−) the shadow before blur is applied. Negative spread is the pro trick that keeps big-blur shadows tight to the element instead of bleeding everywhere.
- color + opacity — almost always black at low opacity (8–25%). Low opacity is what separates “designed” shadows from “drop shadow” clip-art.
Offset vs Blur vs Spread: The Mental Model
Think of the shadow as a copy of the element’s silhouette. Offset moves that copy. Blur smears its edges outward in every direction. Spread scales the copy before smearing. A hard-edge offset shadow (4px 4px, blur 0) gives the retro “sticker” look; a zero-offset, high-blur, negative-spread shadow gives the modern “soft float”; a zero-offset, zero-blur, positive-spread gives a solid ring (useful for inset effects). When a shadow looks wrong, ask which of the three dials is off — it is usually too much spread with too little blur.
Opacity: Why rgba Beats Solid Colors
A solid #000 shadow at 100% looks like a hole punched in the page. Real-world shadows are faint — ambient light diffuses them — which is why production UI lives in the 8–30% opacity range. Using rgba(0,0,0,alpha) instead of a pre-darkened gray also means the shadow blends with whatever is underneath: over white it reads light, over a tinted background it picks up that tint automatically. The opacity slider here drives exactly that alpha channel.
Inset Shadows and Neumorphism
The inset keyword flips the shadow from outside the element to inside it — the classic uses are pressed-in input fields and progress-bar tracks. Push the idea further and you get neumorphism: a light inset from the top-left plus a dark drop to the bottom-right (or vice versa) makes a surface look extruded out of, or carved into, the background. Two warnings: neumorphism fails contrast checks for text, and inset shadows need low offsets to avoid banding on large elements.
Material-Style Elevation Recipes That Work
Google’s Material Design popularized a numbered elevation ladder, and the values behind it are worth stealing. Three of the presets in this tool map directly:
- Resting card (elevation 1–2):
0 4px 6px -1px rgba(0,0,0,0.1)— barely there, separates lists from background. - Floating card (elevation 3–4):
0 10px 25px -5px rgba(0,0,0,0.15)— the default here; the workhorse for modals and hover states. - Dialog / FAB (elevation 6+):
0 20px 50px -10px rgba(0,0,0,0.25)— unmistakably “above everything”.
Use the ladder consistently: the bigger the blur, the fewer the elements that earn it.
Shadows and Performance
Large blur radii are one of the more expensive paint operations in CSS — a 100px blur on hundreds of list items shows up in scroll profiling. Mitigations: prefer one well-tuned shadow over three stacked layers, keep blur under ~50px for repeated elements, and animate transform + opacity instead of transitioning the box-shadow itself when you need 60fps hover effects. (Transitioning between two shadows is fine for a single card; it is the 200-card list that hurts.)
Step-by-Step: Using the Box Shadow Generator
- Start from a preset. Hit Random Preset until you land near the vibe — subtle drop, soft float, sharp edge, long drop, inset, or a colored glow.
- Adjust the offsets. Keep x at 0 for neutral UI light; add y for lift.
- Balance blur and spread. Bigger blur usually wants negative spread to stay contained.
- Set color and opacity. Black at 10–25% for realism; a brand hue at higher opacity for glows.
- Check the preview on the sample card, then toggle inset if you want the inner-shadow variant.
- Copy the CSS and paste it in — or store it as a design-system variable.
Ready to Create Your Box Shadow?
You know what each of the five values does, why low-opacity rgba wins, how inset enables soft-UI effects, and which elevation recipe fits a card versus a dialog. Scroll back up, drag the sliders, and copy a production-ready box-shadow in seconds.
