CSS Box Shadow Generator
Compose ordered CSS box-shadow layers and compare blur and spread in a live preview before copying a stylesheet rule or reusable design token.{{ summaryTitle }}
{{ summaryLine }}
{{ primaryCopyAnnouncement }}
{{ computation.values.css_code }}
The chart renderer is unavailable. Layer values remain available in the preview and ledger.
| Layer | State | Type | Offset | Blur / spread | Color | CSS fragment | Copy |
|---|---|---|---|---|---|---|---|
| {{ row.label }} | {{ row.state }} | {{ row.type }} | {{ row.offset }} | {{ row.blur_spread }} | {{ row.color }} | {{ row.fragment }} |
A box shadow changes how an element relates to the surface around it. A small, tight shadow can separate a card from its background; a broad, faint shadow can suggest ambient elevation; a sharp offset creates a graphic edge; and an inset shadow makes the surface appear recessed.
The effect comes from several values working together. Horizontal and vertical offsets move the shadow, blur softens its edge, spread expands or contracts its starting shape, and color opacity controls visual weight. Changing only one value can alter the apparent depth more than adding another layer.
| Value | Visual effect | Common mistake |
|---|---|---|
| X and Y offset | Moves an outer shadow left, right, up, or down | Using a large offset where a centered glow was intended |
| Blur radius | Widens and softens the edge | Increasing opacity to compensate for an over-wide blur |
| Spread radius | Expands positive values and contracts negative values before blur | Treating spread as another offset |
| Inset | Paints the effect inside the element | Using an inner shadow when the element should appear raised |
Multiple shadows are painted front to back. The first entry sits closest to the element and later entries appear behind it. That order is useful for pairing a tight contact shadow with a larger ambient shadow, but it also means reordering identical values can change the result.
Shadow is a supporting cue, not a complete interaction state. Focus, error, pressed, and disabled states still need visible outlines, borders, text, or other non-shadow signals. Shadows can disappear in forced-colors mode and can be clipped by ancestor overflow in a real layout.
How to Use This Tool:
Build the visual effect first, then choose the code wrapper needed by the stylesheet.
- Load the closest Shadow preset or keep the current custom stack. Presets are editable starting points rather than design standards.
- Open each layer and set X offset, Y offset, blur, spread, color, opacity, and inset mode. Disable a layer to compare the stack without deleting its values.
- Reorder layers when a tight edge should sit in front of a broad shadow. Add or duplicate only when the new layer has a distinct job.
- Choose the Code format and enter the selector used by rule, custom-property, cascade-layer, or SCSS output.
- Try the preview on a surface close to the real component background, then copy the declaration and verify it in the production layout.
Interpreting Results:
Read the generated box-shadow value as the source of truth. The preview helps compare weight and edge softness, while the layer profile makes redundant blur and spread values easier to spot. Labels such as Soft elevation, Deep elevation, Glow stack, and Hard edge are design aids derived from the current values, not CSS categories.
- Test the declaration against the real background and neighboring content.
- Check ancestor
overflow, border radius, and clipping when the outer shadow appears cut off. - Reduce opacity or separate blur sizes when several layers merge into one muddy edge.
- Keep a border or outline for any state that must remain visible without shadows.
Technical Details:
The CSS value is an ordered, comma-separated list. Every enabled layer becomes one shadow fragment; disabled layers remain in the editing ledger but are omitted from the declaration. If all layers are disabled, the result is box-shadow: none;.
Transformation Core
Each enabled row is serialized in CSS order. The optional inset keyword comes first, followed by horizontal offset, vertical offset, blur radius, spread radius, and an explicit RGBA color.
inset? x-offset y-offset blur-radius spread-radius rgba(red, green, blue, alpha)
Hex color channels are converted to decimal red, green, and blue values. Opacity is written as alpha rounded to two decimal places. Length values are rounded to at most two decimals and use pixels.
| Input | Accepted range or form | Output effect |
|---|---|---|
| Layers | 1 to 12 stored rows | Only enabled rows are serialized. |
| X and Y offset | −200px to 200px | Signed displacement in each direction |
| Blur | 0px to 240px | Zero is sharp; negative blur is invalid. |
| Spread | −120px to 120px | Negative values contract; positive values expand. |
| Color | #RRGGBB | Converted to RGBA with the layer opacity |
| Opacity | 0 to 1, inclusive | Zero is transparent; one is fully opaque. |
Selector text is trimmed, repeated whitespace is collapsed, braces and semicolons are removed, and the result is limited to 120 characters. An empty selector falls back to .shadow-card. The same ordered shadow list can be wrapped as a selector rule, declaration, CSS custom property, @layer utility, or SCSS variable without changing the layer values.
Preview shape, surface, width, height, and radius do not change the generated shadow. They only provide a comparison surface, so they cannot model every stacking context, overflow boundary, transformed ancestor, or page background.
Worked Examples:
Quiet card elevation
A tight layer such as 0 2px 5px -2px can define the contact edge, while a second low-opacity layer with much more blur provides ambient separation. Keeping the broad layer behind the tight one preserves a readable edge.
Recessed input
Two inset layers can pair a soft inner shadow with a one-pixel colored spread. The combination may suggest depth and focus, but the input still needs a visible border or outline so the state survives forced colors.
References:
- CSS Backgrounds and Borders Module Level 3, Drop Shadows, W3C, March 11, 2024.
- How to support forced colors mode with CSS, Simplified Guide.