Box Shadow Generator
Create beautiful CSS box-shadow effects with multiple layers for your web design projects.
Shadow Layers
Preview
CSS Code
box-shadow: 0px 4px 6px -1px rgba(0, 0, 0, 0.1), 0px 2px 4px -2px rgba(0, 0, 0, 0.1);What Is a CSS Box Shadow?
The CSS box-shadow property lets you attach one or more drop shadows to any HTML element. Each shadow is positioned relative to the element's border box and rendered behind it, giving depth, focus, and visual hierarchy to cards, buttons, modals, and any block-level element on a page.
Unlike traditional image-based shadows, CSS box shadows are resolution-independent, fully animatable, and require zero extra markup. They respond instantly to hover states, transitions, and media queries, making them indispensable in modern responsive design. This box shadow generator lets you compose multi-layer shadows visually and copy production-ready CSS in one click.
A single box-shadow declaration can carry up to five parameters per layer, plus an optional inset keyword that flips the shadow to the inside of the element — useful for pressed-button effects, input focus rings, and inner-glow treatments. Layers are comma-separated, painted from last to first, so the first layer in the list appears on top.
Understanding how each parameter interacts is essential for producing shadows that look natural rather than harsh. Real-world light sources rarely produce perfectly crisp, uniform shadows; they feather at the edges and shift in intensity based on distance from the surface. The blur and spread parameters give you precise control over this behaviour, while the rgba color notation — including a separate opacity channel — lets you create shadows that blend correctly on any background without hardcoding a semi-transparent flat color.
How the Box Shadow Formula Works
This generator computes the CSS output using the following formula for each shadow layer. The hex color input is split into its red, green, and blue byte pairs and parsed as base-16 integers to build a proper var(--card-bg) value with a separate opacity control:
Single-Layer Box Shadow Output
Where:
- inset= Optional keyword — moves the shadow inside the element's border
- offsetX= Horizontal offset in pixels; positive = right, negative = left
- offsetY= Vertical offset in pixels; positive = down, negative = up
- blur= Blur radius (px, min 0); larger values produce softer, more diffuse shadows
- spread= Spread radius (px); positive expands the shadow, negative contracts it
- R, G, B= Red, Green, Blue channels parsed from the hex color (0–255 each)
- opacity= Alpha transparency (0 = fully transparent, 1 = fully opaque)
Hex-to-RGBA Color Conversion
The generator converts your hex color picker value into an var(--card-bg) color by slicing the six-digit hex string into three two-character byte pairs and parsing each as a base-16 integer. For example, the hex value #3b82f6 becomes rgba(59, 130, 246, opacity) because:
- 3b in base 16 = 3 × 16 + 11 = 59 (red channel)
- 82 in base 16 = 8 × 16 + 2 = 130 (green channel)
- f6 in base 16 = 15 × 16 + 6 = 246 (blue channel)
Separating the alpha into its own opacity slider (rather than using an 8-digit hex code like #3b82f680) gives you finer live control. You can tweak transparency without switching between color formats, and the output is compatible with every major browser including those that lag behind in CSS Color Level 4 support.
When multiple layers are present, each shadow string is generated independently and then joined with a comma delimiter. The CSS result is a single box-shadow declaration with all layers inline, which the browser renders from first to last — the topmost visible shadow is the first entry in the list.
Single-Layer vs. Multi-Layer Shadow Techniques
A single shadow is fine for simple elevation cues, but professional UI kits almost always use two or more layers to mimic how light behaves in the physical world. Tailwind CSS's built-in shadow scale, Google's Material Design elevation system, and Apple's HIG all rely on layered shadows.
The core pattern pairs a large, soft ambient shadow with a small, sharp direct shadow:
- Ambient layer: large blur, slight negative spread, low opacity — simulates diffuse environmental light
- Direct layer: small blur, tighter spread, slightly higher opacity — simulates the key light source
This two-layer approach is why the generator's default state ships with two shadow entries. You can add up to five layers to produce very deep or stylised effects such as long flat shadows, coloured glow rings, or stacked-paper depth.
The inset checkbox switches a layer to an inner shadow, rendered on the inside face of the border box. Inner shadows are ideal for sunken inputs, pressed-state buttons, and inner glow effects. You can freely mix inset and outer layers in the same declaration; the browser renders each according to its own keyword.
Negative spread values are also worth noting: they shrink the shadow smaller than the element itself, which prevents the shadow from peeking out on sides where no light would realistically fall. This is the technique behind the Medium and Large presets in this generator.
Built-In Presets and Practical Use Cases
The generator ships four named presets that cover the most common UI needs. Each preset is a direct translation of widely-used design system values:
| Preset | Layers | Typical Use |
|---|---|---|
| Small | 1 layer: 0 1 3 0 / 0.1 | Subtle card lift, table row hover |
| Medium | 2 layers: 0 4 6 -1 + 0 2 4 -2 / 0.1 | Standard card, dropdown, tooltip |
| Large | 2 layers: 0 10 15 -3 + 0 4 6 -4 / 0.1 | Modal dialog, popover panel |
| Elevated | 1 layer: 0 25 50 -12 / 0.25 | Hero cards, floating action buttons |
Beyond these presets, common creative applications include colored glow effects (set the shadow color to a vibrant hue and increase blur), neumorphic design (pair one light-colored shadow at negative offsets with one dark-colored shadow at positive offsets), and long flat shadows (stack many layers at incremental 1px offset steps with zero blur). The box shadow generator handles all of these patterns through the same five parameters per layer.
CSS Output Format and Tailwind Compatibility
The generator produces two ready-to-use code snippets. The primary output is a standard CSS property declaration compatible with all modern browsers and IE 9+:
box-shadow: <layer1>, <layer2>, ...;
The secondary output formats the first shadow layer as a Tailwind CSS arbitrary value using the shadow-[...] syntax, replacing spaces with underscores as required by Tailwind's JIT parser. Note that Tailwind arbitrary shadows only accommodate a single layer natively; for multi-layer effects you need either a custom theme extension in tailwind.config.js or an inline style attribute.
When pasting the CSS output, place the box-shadow property inside the selector that targets your element. For hover or focus variants in plain CSS, duplicate the property inside a :hover or :focus block and pair it with a transition: box-shadow 0.2s ease; declaration on the base element for smooth animation.
Worked Examples
Small Subtle Shadow (Single Layer)
Problem:
Generate the CSS for a card with a small, barely-visible lift: offsetX=0, offsetY=1, blur=3, spread=0, color=var(--foreground)000, opacity=0.1, inset=false.
Solution Steps:
- 1Parse hex var(--foreground)000 → R=parseInt('00',16)=0, G=parseInt('00',16)=0, B=parseInt('00',16)=0
- 2Build rgba string: var(--card-border)
- 3inset is false, so no 'inset ' prefix
- 4Assemble shadow string: 0px 1px 3px 0px var(--card-border)
- 5Wrap as CSS: box-shadow: 0px 1px 3px 0px var(--card-border);
Result:
box-shadow: 0px 1px 3px 0px var(--card-border);
Medium Two-Layer Elevation Shadow
Problem:
Generate the CSS for a standard elevated card using two layers: Layer 1 — offsetX=0, offsetY=4, blur=6, spread=-1, color=var(--foreground)000, opacity=0.1. Layer 2 — offsetX=0, offsetY=2, blur=4, spread=-2, color=var(--foreground)000, opacity=0.1.
Solution Steps:
- 1Both layers use var(--foreground)000 → R=0, G=0, B=0 for each
- 2Layer 1 string: 0px 4px 6px -1px var(--card-border)
- 3Layer 2 string: 0px 2px 4px -2px var(--card-border)
- 4Join with comma separator
- 5Final CSS: box-shadow: 0px 4px 6px -1px var(--card-border), 0px 2px 4px -2px var(--card-border);
Result:
box-shadow: 0px 4px 6px -1px var(--card-border), 0px 2px 4px -2px var(--card-border);
Colored Inset Glow (Inner Shadow)
Problem:
Create an inset blue focus-ring shadow: offsetX=0, offsetY=4, blur=8, spread=0, color=#3b82f6, opacity=0.5, inset=true.
Solution Steps:
- 1Parse hex #3b82f6 → R=parseInt('3b',16)=59, G=parseInt('82',16)=130, B=parseInt('f6',16)=246
- 2Build rgba string: rgba(59, 130, 246, 0.5)
- 3inset is true, so prepend 'inset '
- 4Assemble shadow string: inset 0px 4px 8px 0px rgba(59, 130, 246, 0.5)
- 5Wrap as CSS: box-shadow: inset 0px 4px 8px 0px rgba(59, 130, 246, 0.5);
Result:
box-shadow: inset 0px 4px 8px 0px rgba(59, 130, 246, 0.5);
Elevated Hero Card Shadow
Problem:
Replicate the Elevated preset: offsetX=0, offsetY=25, blur=50, spread=-12, color=var(--foreground)000, opacity=0.25, inset=false.
Solution Steps:
- 1Parse hex var(--foreground)000 → R=0, G=0, B=0
- 2Build rgba string: rgba(0, 0, 0, 0.25)
- 3inset is false, no prefix
- 4Assemble: 0px 25px 50px -12px rgba(0, 0, 0, 0.25)
- 5Final CSS: box-shadow: 0px 25px 50px -12px rgba(0, 0, 0, 0.25);
Result:
box-shadow: 0px 25px 50px -12px rgba(0, 0, 0, 0.25);
Tips & Best Practices
- ✓Use two shadow layers — a large soft ambient layer and a small sharp direct layer — for the most realistic depth effect.
- ✓Negative spread values (e.g., -3px to -6px) keep shadows from bleeding sideways on elements with only a bottom light source.
- ✓Keep opacity below 0.2 for subtle UI shadows; reserve values above 0.3 for dramatic hero card or modal elevation.
- ✓Try a colored shadow (e.g., brand blue or purple) on primary action buttons to create a vibrant glow that guides user attention.
- ✓Add <code>transition: box-shadow 0.15s ease;</code> on interactive elements so shadows animate smoothly on hover without any JavaScript.
- ✓Combine an outer drop shadow with an inset highlight (white, low opacity, offsetY=-1) on the top edge to simulate a bevelled surface.
- ✓For neumorphic design, pair a soft light shadow (white, offset top-left) with a dark shadow (grey, offset bottom-right) at identical blur and spread values.
- ✓Test your shadows in both light and dark mode — a black shadow at 0.1 opacity reads well on white but may be invisible on a dark background; consider a lighter shadow color for dark themes.
Frequently Asked Questions
Sources & References
Last updated: 2026-06-05
Help us improve!
How would you rate the Box Shadow Generator?
Editorial Note
MyCalcBuddy Editorial Team
This page is maintained as an educational calculator reference.
Formula Source: Standard Mathematical References
by Various