๐ CSS Box Shadow Generator with Live Preview
By Shihab Mia ยท Updated 2026-06-27
Drag the sliders or pick a color. The preview and CSS update live.
This CSS box shadow generator lets you build a box-shadow value visually instead of guessing numbers by hand. Drag the sliders for horizontal and vertical offset, blur, and spread, pick a shadow color, set its opacity, and flip the inset toggle for an inner shadow. A live preview shows exactly how the shadow looks, and one click copies the ready-to-paste CSS. Everything runs in your browser, so nothing you build is ever sent to a server.
What is the CSS Box Shadow Generator?
The CSS box-shadow property draws a shadow around an element's box. A single shadow is written as up to five parts in this order: horizontal offset, vertical offset, blur radius, spread radius, and color, optionally preceded by the inset keyword. For example, box-shadow: 10px 10px 20px 0px rgba(30, 41, 59, 0.4) pushes the shadow 10px right and 10px down, softens it with 20px of blur, leaves the spread at 0, and uses a dark slate color at 40% opacity. Only the two offsets and a color are technically required; blur and spread default to 0 if you omit them.
Each value does a distinct job. The horizontal and vertical offsets move the shadow relative to the element, where positive values go right and down and negative values go left and up. The blur radius controls how soft the edge is, with 0 giving a hard edge and larger numbers giving a soft, diffuse glow. The spread radius grows (positive) or shrinks (negative) the shadow before the blur is applied, which is handy for tight ambient shadows or for pulling a shadow back so it peeks out evenly on all sides. The color, usually written as rgba() or hsla() so you can control opacity, sets the tone. Semi-transparent dark colors read as natural shadows, while bright saturated colors read as glows or focus rings.
The inset keyword flips the shadow inward, painting it inside the element's padding box rather than outside the border. Outer shadows make a card or button appear to float above the page, while inset shadows make an element look recessed, like a pressed key, a text input well, or an inner bevel. You can stack several shadows on one element by separating them with commas, and the browser paints them from the last listed shadow upward, so the first shadow in the list sits on top. Layering is how designers build realistic depth instead of a single flat smudge.
Professional design systems lean heavily on layered shadows. Google's Material Design defines roughly two dozen elevation levels, each built from three stacked shadows that mimic a key light, a fill light, and ambient occlusion, producing depth that a single shadow cannot match. A typical Material elevation looks like box-shadow: 0 1px 2px rgba(0,0,0,0.30), 0 4px 8px rgba(0,0,0,0.25), 0 16px 32px rgba(0,0,0,0.20). The trick is to combine a tight, slightly darker contact shadow with one or two wider, lighter ambient shadows so the object feels grounded yet lifted.
The soft UI style known as neumorphism pushes the same idea further by using two opposing shadows on a matching background. One light shadow is offset toward the top left to simulate a light source and one dark shadow is offset toward the bottom right, which makes an element appear extruded from or pressed into a single continuous surface, for example box-shadow: 8px 8px 16px #d1d9e6, -8px -8px 16px #ffffff. Adding the inset keyword to both shadows produces the pressed-in variant used for active states. Glow effects use the opposite recipe: a bright color, generous blur, zero offset, and often a small spread so the halo sits evenly around the element, which is exactly how focus rings and neon buttons are built.
Box-shadow is not the only way to cast a shadow. The filter: drop-shadow() function follows the actual alpha shape of an element, so it wraps transparent PNGs, rounded corners, and irregular silhouettes rather than the rectangular bounding box that box-shadow always uses. Box-shadow is faster to paint, supports inset and spread, and accepts multiple comma-separated values, so it remains the right choice for cards, buttons, and inputs, while drop-shadow is better for logos and cut-out images. Box-shadow has near universal browser support back to early Internet Explorer, draws outside layout flow so it never affects element size or position, and respects border-radius automatically. For performance, keep the stack to roughly two to five shadows per element since each one adds paint cost, and avoid animating blur or spread directly because that forces repeated repaints; animate opacity or swap pre-baked shadow values instead.
When to use it
- Designing a subtle drop shadow for cards, buttons, modals, or dropdowns without trial-and-error in dev tools.
- Creating an inset shadow to make text inputs, toggles, or pressed buttons look recessed.
- Building realistic depth with Material Design style elevation by layering two or three stacked shadows.
- Crafting neumorphic (soft UI) elements that appear extruded from or pressed into a matching background.
- Prototyping a soft glow, neon, or focus-ring effect using a bright color with high blur and zero offset.
- Teaching or learning how each box-shadow value (offset, blur, spread, inset) changes the rendered result.
How to use the CSS Box Shadow Generator
- Drag the horizontal and vertical offset sliders to position the shadow relative to the element.
- Adjust the blur slider to soften the edge and the spread slider to grow or shrink it.
- Pick a shadow color and set its transparency with the opacity slider for a natural look.
- Toggle Inset if you want an inner shadow instead of an outer one.
- Watch the live preview update in real time, then click Copy to grab the box-shadow CSS.
- To layer shadows, copy this value, then paste a second comma-separated shadow after it.
Formula & method
Worked examples
A soft floating card shadow: 10px right, 10px down, 20px blur, no spread, dark slate at 40% opacity.
- Color #1e293b converts to rgb(30, 41, 59).
- Opacity 40% becomes an alpha of 0.4.
- Combine the values in order: 10px 10px 20px 0px rgba(30, 41, 59, 0.4).
Result: box-shadow: 10px 10px 20px 0px rgba(30, 41, 59, 0.4);
A pressed inset shadow: no offset, 8px blur, 2px spread, black at 30% opacity.
- Color #000000 converts to rgb(0, 0, 0).
- Opacity 30% becomes an alpha of 0.3.
- Add the inset keyword first, then the values: inset 0px 0px 8px 2px rgba(0, 0, 0, 0.3).
Result: box-shadow: inset 0px 0px 8px 2px rgba(0, 0, 0, 0.3);
A Material Design style elevation built from three stacked shadows for realistic depth.
- Start with a tight contact shadow: 0 1px 2px black at 30% opacity.
- Add a mid ambient shadow: 0 4px 8px black at 25% opacity.
- Add a wide ambient shadow: 0 16px 32px black at 20% opacity, separating each with a comma.
Result: box-shadow: 0 1px 2px rgba(0,0,0,0.30), 0 4px 8px rgba(0,0,0,0.25), 0 16px 32px rgba(0,0,0,0.20);
A neumorphic (soft UI) raised button on a light gray background using two opposing shadows.
- Offset a dark shadow toward the bottom right: 8px 8px 16px using #d1d9e6.
- Offset a light shadow toward the top left: -8px -8px 16px using #ffffff.
- Use the same background color on the element and the page so the effect reads as one surface.
Result: box-shadow: 8px 8px 16px #d1d9e6, -8px -8px 16px #ffffff;
What each box-shadow value controls
| Value | Effect | Notes |
|---|---|---|
| Horizontal offset | Moves the shadow left or right | Positive moves right, negative moves left |
| Vertical offset | Moves the shadow up or down | Positive moves down, negative moves up |
| Blur radius | Softens the shadow edge | Must be 0 or positive; larger is softer |
| Spread radius | Grows or shrinks the shadow | Positive expands, negative contracts |
| Color | Sets the shadow tone and opacity | Use rgba() or hsla() for transparency |
| inset | Draws the shadow inside the element | Omit it for a normal outer shadow |
Shadow recipes for common UI patterns
| Effect | Example box-shadow value | When to use |
|---|---|---|
| Subtle card | 0 1px 3px rgba(0,0,0,0.12) | Resting cards, list items, panels |
| Raised button | 0 4px 8px rgba(0,0,0,0.15) | Default buttons and tiles |
| Modal / popover | 0 10px 25px rgba(0,0,0,0.2) | Dropdowns, dialogs, floating menus |
| Inset well | inset 0 2px 4px rgba(0,0,0,0.2) | Text inputs and pressed states |
| Focus ring | 0 0 0 3px rgba(59,130,246,0.5) | Keyboard focus and active outlines |
| Soft glow | 0 0 20px rgba(59,130,246,0.6) | Neon, hover highlights, call-to-action |
box-shadow vs filter: drop-shadow()
| Aspect | box-shadow | drop-shadow() |
|---|---|---|
| Shadow shape | Follows the rectangular box (respects border-radius) | Follows the actual alpha silhouette |
| Transparent PNGs | Shadows the bounding box, not the cut-out | Wraps the visible shape correctly |
| Inset support | Yes, via the inset keyword | No inset option |
| Spread radius | Supported | Not supported |
| Multiple shadows | Comma-separated in one property | Chain multiple drop-shadow() filters |
| Best for | Cards, buttons, inputs, layered depth | Logos, icons, irregular cut-out images |
Common mistakes to avoid
- Writing a negative blur radius. The blur radius cannot be negative. CSS treats a negative value as invalid and ignores the whole shadow, so keep blur at 0 or higher and use a negative spread when you want to shrink it.
- Getting the value order wrong. The order is offset-x, offset-y, blur, spread, color. Swapping offset and blur, or putting the color first, produces a different shadow or breaks the rule entirely.
- Using a fully opaque color. A solid color like #000 often looks harsh and flat. Real shadows are semi-transparent, so use rgba() with an alpha around 0.1 to 0.4 for a natural look.
- Expecting inset to push the box outward. The inset keyword paints the shadow inside the element. If you want the box to appear lifted off the page, remove inset and use an outer shadow instead.
- Relying on one heavy shadow for depth. A single dark blur looks like a smudge. Stack two or three lighter shadows at different blur radii so the element gets a tight contact shadow plus a soft ambient one.
- Forgetting that box-shadow ignores transparent shapes. box-shadow always traces the rectangular box. For a transparent PNG, rounded badge, or irregular logo, use filter: drop-shadow() so the shadow follows the visible silhouette.
Glossary
- box-shadow
- The CSS property that draws one or more shadows around an element box, set by offset, blur, spread, and color values.
- Offset
- How far the shadow is shifted from the element, given as a horizontal and a vertical distance.
- Blur radius
- How far the shadow edge is softened. A value of 0 gives a sharp edge; larger values diffuse it.
- Spread radius
- A value that expands (positive) or contracts (negative) the shadow size before blur is applied.
- Inset
- A keyword that makes the shadow appear inside the element, giving a recessed or pressed look.
- rgba()
- A color notation taking red, green, blue, and an alpha (opacity) channel from 0 to 1.
- Elevation
- A design-system concept where higher surfaces cast larger, softer shadows, popularized by Material Design.
- Neumorphism
- A soft UI style using two opposing shadows on a matching background so elements look extruded or pressed in.
Frequently asked questions
What is a CSS box shadow generator?
It is a visual tool that builds the CSS box-shadow value for you. You adjust offset, blur, spread, color, and opacity with controls, see a live preview, and copy the resulting code instead of writing it by hand.
How does the CSS box-shadow property work?
box-shadow takes up to five parts in order: horizontal offset, vertical offset, blur radius, spread radius, and color, optionally led by the inset keyword. Only the two offsets and a color are required; blur and spread default to 0.
What does the inset keyword do?
Inset draws the shadow inside the element rather than outside, so the box looks recessed or pressed in. Without inset, the shadow sits outside and the element appears to float above the page.
What is the difference between blur and spread?
Blur softens the shadow edge so it fades out gradually, while spread changes the shadow size before blur is applied. Positive spread makes the shadow larger; negative spread makes it smaller, which is useful for tight, even ambient shadows.
How do I add multiple box shadows to one element?
List several shadows separated by commas in a single box-shadow rule, for example box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 16px rgba(0,0,0,0.2). The browser paints them from the last listed upward, so the first shadow sits on top. Layering tight and wide shadows creates realistic depth.
How do I create a Material Design elevation shadow?
Stack three shadows: a tight contact shadow, a mid ambient shadow, and a wide ambient shadow, each slightly lower in opacity. A common example is box-shadow: 0 1px 2px rgba(0,0,0,0.30), 0 4px 8px rgba(0,0,0,0.25), 0 16px 32px rgba(0,0,0,0.20). Higher elevation means larger offsets and blur.
How do I make a neumorphic (soft UI) shadow?
Use two shadows on an element that shares the page background: a dark one offset toward the bottom right and a light one offset toward the top left, such as box-shadow: 8px 8px 16px #d1d9e6, -8px -8px 16px #ffffff. Add inset to both for the pressed-in variant.
How do I create a glow effect with box-shadow?
Set both offsets to 0, use a bright saturated color, and apply a large blur, for example box-shadow: 0 0 20px rgba(59,130,246,0.6). Add a small spread to make the halo even on all sides. This same recipe builds focus rings and neon buttons.
What is the difference between box-shadow and filter: drop-shadow()?
box-shadow traces the rectangular box and respects border-radius, supports inset and spread, and accepts multiple comma-separated values. filter: drop-shadow() follows the actual alpha shape, so it wraps transparent PNGs and irregular silhouettes but cannot do inset or spread.
Does box-shadow affect the element size or layout?
No. The shadow is painted outside the normal layout flow, so it never changes the element width, height, or position and never pushes neighboring elements. That is why a wide shadow can overlap adjacent content without reflowing the page.