🎨 CSS & Design

CSS Box Shadow Generator

Drag the sliders to design a shadow, then copy clean box-shadow CSS.

  • 6presets
  • 2shadow layers
  • ±60pxoffsets
  • 0–120pxblur
Presets

    

How to use the Box Shadow Generator

  1. 1

    Start with a preset

    Soft, Subtle, Floating, Neo-brutal, Inner or Glow set all values at once.

  2. 2

    Adjust the shadow

    Change x and y offset, blur, spread, opacity and colour; tick Inset for an inner shadow.

  3. 3

    Match your page

    Set the box colour, corner radius and background so the preview looks like your real design.

  4. 4

    Copy the CSS

    You get the box-shadow line (one or two layers) plus the border-radius you previewed.

Features

Two-layer realism

An optional contact layer — 0 1px 3px at up to 12% opacity — sits under the main shadow.

Colour + opacity

Shadow colour is converted to rgba() with your chosen opacity, or plain hex at 100%.

Inset option

Applies inset to both layers for pressed buttons and sunken input fields.

Glow preset

Zero offset with a coloured blur and positive spread for focus or neon effects.

Neo-brutal preset

A solid black 6px offset with no blur, for flat retro designs.

Realistic preview

Custom box and page colours show how the shadow reads in context.

Who uses it — and for what

Cards

Give content cards gentle elevation off the page.

Menus and dialogs

Use deeper shadows to show layers above the page.

Buttons

Create hover lift or pressed inset states.

Focus and highlights

Use a glow to draw attention to a selected element.

What each value does

A shadow is written as box-shadow: x y blur spread colour. The offsets move it right/down (negative values move it left/up). Blur softens the edge — bigger numbers give a diffuse, floating look. Spread grows or shrinks the shadow before it is blurred; a small negative spread with a large blur keeps the shadow tucked under the element so it doesn’t leak out at the sides. Inset draws the shadow inside the box, which is how pressed buttons and input fields get their sunken look.

Tips for natural-looking shadows

  • Use a dark, slightly blue or brand-tinted colour at 10–25% opacity rather than pure black at high opacity.
  • Real objects cast two shadows: a tight, darker contact shadow and a wide, soft ambient one. Tick “contact layer” to stack both.
  • Keep the light source consistent — if one card’s shadow falls down, they all should.
  • Bigger elevation = larger y-offset and blur, used sparingly for menus and dialogs.

Everything updates live as you drag — copy the code when it looks right. Nothing is uploaded and there is no sign-up.

Animating shadows without jank

Changing box-shadow on hover is common, but the browser has to repaint the shadow on every frame of a transition. Large blurs on many elements at once can stutter on slower phones. Two techniques help:

  • Keep transitions short and few. A 150–250 ms shadow change on one hovered card is rarely a problem; animating shadows on dozens of items while scrolling is.
  • Fade a pseudo-element instead. Put the larger shadow on ::after with opacity: 0, and animate only its opacity on hover. Opacity is one of the properties browsers can animate cheaply.
.card { position: relative; box-shadow: var(--shadow-1); }
.card::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: var(--shadow-3); opacity: 0; transition: opacity 0.2s;
}
.card:hover::after { opacity: 1; }

The pseudo-element has no background, so the card’s content stays visible while the bigger shadow fades in around it. Combined with a small transform: translateY(-2px), this gives a smooth “lift”.

Shadows in dark mode and on transparent images

Shadows rely on the background being lighter than the shadow. On a dark page, a dark shadow barely shows, so dark themes usually show depth differently:

  • Make raised surfaces slightly lighter than the page (for example a card one or two steps lighter than the background).
  • Use a subtle 1px border in a light, low-opacity colour to define edges.
  • Keep a shadow for large overlays like dialogs, but raise its opacity — what looks right at 22% on white may need 50% or more on near-black.

Set the Background control to your dark page colour to test this in the preview.

box-shadow always follows the element’s box (including its border-radius), not the visible pixels of its content. For a transparent PNG logo or an irregular SVG icon, it draws a rectangle-shaped shadow. Use filter: drop-shadow(…) there instead — it follows the actual shape. The CSS Filter Generator can build that. For shadows on text, use the Text Shadow Generator.

Worked examples

Preset outputs

Presetbox-shadow value
Soft0 1px 3px rgba(15, 23, 42, 0.11), 0px 12px 32px -6px rgba(15, 23, 42, 0.22)
Subtle0 1px 3px rgba(15, 23, 42, 0.06), 0px 2px 8px 0px rgba(15, 23, 42, 0.12)
Floating0 1px 3px rgba(30, 27, 75, 0.12), 0px 30px 60px -12px rgba(30, 27, 75, 0.3)
Neo-brutal6px 6px 0px 0px #000000
Innerinset 0px 4px 12px 0px rgba(15, 23, 42, 0.25)
Glow0px 0px 40px 4px rgba(99, 102, 241, 0.6)

The contact layer’s opacity is half the main opacity, capped at 12%: Subtle at 12% gives a 6% contact layer, Floating at 30% hits the 12% cap.

A shadow scale for elevation

Instead of inventing a shadow for every component, define a few levels and reuse them. Built with this tool’s presets:

:root {
  --shadow-1: 0 1px 3px rgba(15, 23, 42, 0.06), 0px 2px 8px 0px rgba(15, 23, 42, 0.12);
  --shadow-2: 0 1px 3px rgba(15, 23, 42, 0.11), 0px 12px 32px -6px rgba(15, 23, 42, 0.22);
  --shadow-3: 0 1px 3px rgba(30, 27, 75, 0.12), 0px 30px 60px -12px rgba(30, 27, 75, 0.3);
}
.card { box-shadow: var(--shadow-1); }
.card:hover { box-shadow: var(--shadow-2); }
.dialog { box-shadow: var(--shadow-3); }

Pro tips

  • The box radius, box colour and background controls are for preview, but the radius is also included in the copied CSS so the shadow matches.
  • Glow looks best with a colour from your brand and a small positive spread; keep it for one element at a time.
  • Turn the contact layer off for neo-brutal or glow styles, where a soft grey layer would muddy the effect.

Glossary

Elevation
How far an element appears to float above the page, shown with larger and softer shadows.
Contact shadow
A small, darker shadow right where an object meets a surface.
drop-shadow()
A CSS filter that casts a shadow following an element’s visible shape, including transparency.

Frequently asked questions

Can an element have more than one shadow?

Yes — separate shadows with commas. The first one is drawn on top.

Does box-shadow affect layout?

No. Shadows never take up space or move other elements, so they are safe for hover effects.

Why is my shadow cut off?

A parent with overflow: hidden clips it. Add padding to the parent or move the overflow rule.

Why does my shadow show as a rectangle around a transparent PNG?

box-shadow follows the element’s box, not its visible pixels. Use filter: drop-shadow() for images with transparency.

Does Inset apply to both shadow layers?

Yes. When inset is ticked, the contact layer and the main shadow are both drawn inside the box.

Why is the opacity written as a hex colour at 100%?

At full opacity there is no transparency to express, so the tool writes the plain hex colour instead of rgba().

Found it useful? Share the Box Shadow Generator:

Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of CSS & Design (37 tools)