Box Shadow Generator

Create beautiful CSS box-shadow effects with multiple layers for your web design projects.

Shadow Layers

Layer 1
0px
4px
6px
-1px
Layer 2
0px
2px
4px
-2px

Preview

Preview Box

CSS Code

box-shadow
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

[inset] offsetX px offsetY px blur px spread px rgba(R, G, B, opacity)

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:

  1. 1Parse hex var(--foreground)000 → R=parseInt('00',16)=0, G=parseInt('00',16)=0, B=parseInt('00',16)=0
  2. 2Build rgba string: var(--card-border)
  3. 3inset is false, so no 'inset ' prefix
  4. 4Assemble shadow string: 0px 1px 3px 0px var(--card-border)
  5. 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:

  1. 1Both layers use var(--foreground)000 → R=0, G=0, B=0 for each
  2. 2Layer 1 string: 0px 4px 6px -1px var(--card-border)
  3. 3Layer 2 string: 0px 2px 4px -2px var(--card-border)
  4. 4Join with comma separator
  5. 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:

  1. 1Parse hex #3b82f6 → R=parseInt('3b',16)=59, G=parseInt('82',16)=130, B=parseInt('f6',16)=246
  2. 2Build rgba string: rgba(59, 130, 246, 0.5)
  3. 3inset is true, so prepend 'inset '
  4. 4Assemble shadow string: inset 0px 4px 8px 0px rgba(59, 130, 246, 0.5)
  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:

  1. 1Parse hex var(--foreground)000 → R=0, G=0, B=0
  2. 2Build rgba string: rgba(0, 0, 0, 0.25)
  3. 3inset is false, no prefix
  4. 4Assemble: 0px 25px 50px -12px rgba(0, 0, 0, 0.25)
  5. 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

The spread radius expands or contracts the shadow beyond the element's dimensions before the blur is applied. A positive value makes the shadow larger than the element on all four sides, while a negative value shrinks it so the shadow is smaller than the element. Negative spread is frequently used to prevent a bottom-only shadow from leaking sideways, creating a more realistic downward light effect.
An inset shadow is rendered on the inside of the element's border box rather than outside it. It creates the illusion that the element is sunken into the page, which makes it ideal for pressed button states, focused input fields, and inner-glow highlights. You can freely combine inset and outer shadow layers in the same <code>box-shadow</code> declaration.
Add <code>transition: box-shadow 0.2s ease;</code> to the base element and define the hover shadow in a <code>:hover</code> rule. The browser composites box-shadow changes on the GPU without triggering layout or paint, making them smooth even on complex pages. For best performance, avoid animating the spread radius at large values, as very large spread areas can be expensive to render on lower-end devices.
The var(--card-bg) format is supported in all browsers back to IE 9 and offers unambiguous opacity control via a dedicated 0–1 parameter. Eight-digit hex colors (e.g., var(--foreground)00080) are a CSS Color Level 4 feature that is not supported in Internet Explorer and was only added to major browsers around 2016–2018. The var(--card-bg) approach maximises compatibility while keeping the opacity slider intuitive and independent of the hue selection.
Yes, but only for a single shadow layer. The generator outputs the first layer formatted as a Tailwind arbitrary value like <code>shadow-[0px_4px_6px_-1px_rgba(0,0,0,0.1)]</code>. For multi-layer shadows, the best approach is either adding a named entry to the <code>boxShadow</code> key in your <code>tailwind.config.js</code> theme or using an inline <code>style</code> attribute with the full multi-layer CSS output.
No. The CSS <code>box-shadow</code> property is purely visual and has no effect on layout. It does not add to the element's computed dimensions, does not push adjacent elements, and does not affect scrollable overflow. If you need the shadow area to be part of the layout or clickable region, consider using <code>outline</code> or <code>border</code> instead, both of which do influence the box model.
Apply a negative spread value equal in magnitude to the blur radius, then offset the shadow in the desired direction. For example, a bottom-only shadow with blur 8px and spread -8px produces a shadow that is invisible on the top, left, and right sides. Adjust the offsetY to push the shadow further below the element until the desired depth is achieved.

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.

Source

Formula Source: Standard Mathematical References

by Various

UpdatedLast reviewed: May 2026
CheckedFormula checks are based on standard references and internal QA review.