CSS Box Shadow Generator
Create CSS box shadows visually with multiple layers. Adjust blur, spread, offset, color. Free online box-shadow CSS code generator
A good box-shadow is the single biggest difference between "looks like Material Design 2014" and "looks like a 2026 product". The cheat: real-world shadows have two components — a tight close-contact shadow and a soft ambient one. This generator builds CSS box-shadow with multiple layers, previews them on cards/buttons/modals, and offers preset elevation systems (Material 3, Tailwind, Apple HIG) so you do not have to derive shadow scales from scratch.
The two-layer shadow that makes UI look real
Input
A card lifted 8px above the page
Output
Single-layer (looks fake):
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
Two-layer (looks real):
box-shadow:
0 1px 2px rgba(0,0,0,0.08), /* close-contact shadow */
0 8px 16px rgba(0,0,0,0.12); /* ambient shadow */
Three-layer (Material 3 style):
box-shadow:
0 1px 3px rgba(0,0,0,0.10),
0 4px 8px rgba(0,0,0,0.08),
0 16px 24px rgba(0,0,0,0.06);Real-world shadows are not one blob — they have a sharp edge close to the object and softer falloff farther away. CSS box-shadow accepts a comma-separated list; each value renders as a separate shadow layer in z-order (first in the list = topmost). Designers who don't know this give up after one layer and produce "looks like a 2014 card" shadows.
Anatomy of the box-shadow property
`box-shadow: [inset?] <offset-x> <offset-y> <blur> <spread> <color>`
- offset-x — horizontal distance. Positive = right. Usually 0 for natural shadows (the light is from above).
- offset-y — vertical distance. Positive = down. Real-world shadows from overhead lighting have small positive offset-y.
- blur — softness. 0 = sharp edge (looks like a hard cutout); 20-30 = realistic soft shadow.
- spread — extra spread radius. Positive = larger, negative = smaller than the element. Used to "tighten" the shadow under the element.
- color — usually rgba black with low alpha (0.05-0.2). Pure black at high alpha looks like the element is on fire.
- inset (optional) — render INSIDE the element instead of outside. Used for "depressed" buttons, input fields, sunken panels.
Elevation systems and what they encode
- Material 3 — elevations 1-5. Each is a specific 3-layer shadow with carefully-tuned blur/spread. Used by Google's entire product line.
- Tailwind shadow-sm to shadow-2xl — 5-step ramp from "barely there" to "modal-sized". Single-layer shadows; reasonable defaults for utility-class workflows.
- Apple Human Interface Guidelines — system-controlled materials with translucency. iOS/macOS apps use the system blur-and-shadow effects rather than fixed CSS values.
- Custom — define your own scale based on your design system's elevation tokens (e.g., elevation.card, elevation.modal). Document it once; reuse.
Performance considerations
Box-shadows are pixel operations — the browser composites the shadow on a separate layer and blends it. Small static shadows are basically free. Large blurred shadows (blur > 40px) over a large area can cost milliseconds per frame; animating them at 60fps can drop frames.
Two performance tricks: (1) animate `transform` and `opacity` of a child shadow element instead of the shadow itself — those properties are GPU-accelerated and free. (2) for elements that move during animations, use `will-change: box-shadow` or convert the shadow to a filter (filter: drop-shadow) which sometimes performs differently.
When to reach for this tool
- You are designing a new component and want to compare three shadow options visually before committing.
- You inherited a stylesheet with "single-layer 0 4px 8px rgba(0,0,0,0.3)" shadows and want to upgrade them to multi-layer.
- You are tuning a focus-ring or interactive-state shadow (button hover, input focus) and want to preview the transition.
- You are building a design system and need preset elevation tokens that match a specific framework's convention.
What this tool will not do
- It will not redesign your component. The shadow contributes; layout, spacing, color, typography do the rest. A great shadow on a misaligned button is still a misaligned button.
- It will not check accessibility. Shadow is decorative — screen readers ignore it. Focus indicators using ONLY shadow may not meet WCAG (need 3:1 contrast against adjacent colors).
- It will not handle text-shadow. Different property, different syntax (no spread parameter), different use cases. Text-shadow on body text usually looks bad; reserve for headings or specific effects.
Frequently asked questions
Why does my shadow look gray instead of dark?
You are using a low-alpha black on a colored background. The shadow blends with the background — black at 0.1 alpha over a blue background looks blue-gray, not gray. To get a true gray shadow, increase alpha to ~0.3; to get a colored shadow on a colored background, match the shadow color to the background's complement.
Should I use box-shadow or filter: drop-shadow?
box-shadow follows the element's bounding box (rectangle). filter: drop-shadow follows the actual shape including border-radius and transparency. For irregular shapes (icons, SVGs with transparency), drop-shadow looks correct; for rectangular cards, both work. drop-shadow can be slightly slower.
How do I make shadows appear "lit from a specific angle"?
Set offset-x and offset-y to point AWAY from the light source. Light from top-left = shadow toward bottom-right (positive x, positive y). For "lit from above" (the most common assumption), use offset-x: 0 and small positive offset-y.
Can I use box-shadow for inner shadows?
Yes — the `inset` keyword. `box-shadow: inset 0 2px 4px rgba(0,0,0,0.1)` puts a subtle inner shadow at the top of the element, simulating a "depressed" or "concave" surface. Common on form inputs and sunken panels.
How do I do multiple shadows of different colors?
Each shadow in the comma-separated list has its own color. `box-shadow: 0 0 0 2px blue, 0 4px 8px rgba(0,0,0,0.2)` gives a blue focus ring AND a drop shadow simultaneously. Useful for accessible focus states that also retain elevation.
My focus-ring shadow makes the layout shift on focus.
Shadow does not affect layout (does not change element size or push siblings). If your layout shifts, you're probably using `border` instead of `box-shadow` for the focus ring. Switch to a shadow with `0 0 0 2px <color>` — no layout impact, same visual effect.
Related tools
Visual border-radius generator for CSS. Create rounded corners, pills, organic shapes. Generate CSS border-radius code with live preview
Create beautiful linear, radial, conic CSS gradients visually. Copy CSS code instantly. Free online gradient maker with multiple color stops
Check WCAG color contrast accessibility compliance. Extract colors from images. Analyze color palettes for web accessibility. Free color checker
Visual CSS Flexbox layout builder. Configure flex container and items with live preview. Generate flexbox code for responsive layouts. Free online flexbox playground
Pick colors from HEX, RGB, HSL. Generate color palettes and harmonies. Create gradients. Free online color picker and palette maker for designers
Build CSS keyframe animations visually with timeline editor. Create custom @keyframes. Free online CSS animation generator with live preview
Last updated · E-Utils editorial team