Guide
Realistic CSS box shadows for cards, buttons and modals
Shadows tell people what’s on top: a card above the page, a menu above the card, a dialog above everything. Good shadows are barely noticed; bad ones look like gray smudges. This generator lets you build shadows layer by layer, preview them on light and dark backgrounds, and copy the CSS.
Building a shadow
- Start from a preset (Subtle, Card, Raised, Floating, Inset or Glow) or adjust the current one.
- For the selected layer, set:
- Horizontal and Vertical offset: where the light comes from. Most interfaces use a small downward offset, as if light came from above.
- Blur: how soft the edge is.
- Spread: grows (positive) or shrinks (negative) the shadow before blurring.
- Color and Opacity.
- Inset: puts the shadow inside the box.
- Add layers for more realism; select a layer to edit it, or remove it.
- Toggle the dark background to check how it looks in dark mode.
- Copy CSS and paste it into your stylesheet.
Why layered shadows look real
A real object casts a small, dark shadow right underneath and a wider, fainter one further out. One layer can’t do both. The Card and Raised presets combine a tight, low-blur shadow with a larger, softer one, each at low opacity, for example:
box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.06), 0px 4px 12px -2px rgba(0, 0, 0, 0.1);
Negative spread on the larger layer keeps the shadow from peeking out at the sides, so it appears mostly below the element.
An elevation scale
Use a small set of shadows consistently, so depth means something:
| Level | Preset | Use for |
|---|---|---|
| 1 | Subtle | Inputs, list items, flat cards |
| 2 | Card | Cards, panels, tiles |
| 3 | Raised | Hovered cards, dropdown menus |
| 4 | Floating | Dialogs, popovers, toasts |
Save the four values as CSS variables (such as --shadow-1 to --shadow-4) and use only those across the site.
Inset and glow
- Inset shadows make elements look pressed in: text fields, toggles in the “on” state, wells.
- Glow uses a colored shadow with no offset and a wide blur, effective for focus states, highlighted buttons or neon-style designs. Keep it subtle in interfaces.
Shadows and dark mode
Shadows are nearly invisible on dark backgrounds. Preview with dark background on. In dark themes, elevation usually comes from slightly lighter surfaces and thin borders, with shadows used sparingly at higher opacity.
Tips
- Shadow color: pure black at low opacity works, but a very dark version of the background hue looks richer on colored backgrounds.
- Match the light source: use the same direction across the whole interface.
- Performance: static shadows are cheap; avoid animating
box-shadowon many elements. For hover effects, animate the opacity of a pseudo-element that holds the larger shadow. - Border radius: shadows follow the element’s rounded corners automatically.
Who designs shadows
- Front-end developers style cards, dropdowns, modals and buttons.
- UI designers define a consistent elevation scale for a design system.
- No-code site builders paste custom CSS into website builders.
- Students learn CSS by seeing how each value changes the result.
A complete example: a card with a hover effect
- Start with the Card preset for the resting state and copy the CSS.
- Switch to Raised for the hover state and copy that CSS too.
- In your stylesheet, apply the first to
.cardand the second to.card:hover, with a short transition. - Check both on light and dark backgrounds with the preview toggle.
Tips
- Use the same few shadow levels throughout a site.
- Shadows should get larger and softer as elements rise higher.
Related tools
- CSS Gradient Generator for backgrounds.
- Color Converter for shadow colors in rgba or hex.
- PX to REM for converting sizes to rem units.
Checked against the current version of the Box Shadow Generator on .

