A single box-shadow with a large blur makes a card look like it is floating in fog. Objects under real light cast a dark, tight shadow where they almost touch the surface and a wide, faint one from the surrounding light. CSS can draw both, because box-shadow accepts a comma-separated list. Tailwind's own shadow-md is two layers for this reason.
What each value does
A shadow is a copy of the element's border box (with its border-radius) that is offset, grown or shrunk, blurred, and painted behind the element.
/* x-offset y-offset blur spread color */
box-shadow: 0 8px 24px -6px rgb(15 23 42 / 0.2);- Offsets move the copy. Positive y means light from above. Keep x at 0 unless the whole interface uses a side light; mixing directions between components looks wrong quickly.
- Blur softens the edge. The CSS Backgrounds specification defines it as a Gaussian blur with a standard deviation of half the blur radius, so the visible fade is roughly twice the blur value wide, centered on the shadow's edge. A 24px blur fades over about 48px, half of it outside the original edge.
- Spread grows (positive) or shrinks (negative) the copy before blurring. A negative spread is the useful one: it pulls the shadow back under the element so the blur shows below it but barely at the sides.
- Color is usually a black or dark tint with low alpha. If you leave the color out, the shadow uses currentColor, which is rarely what you want.
Some details are easy to miss. In a list, the first shadow is painted on top. Shadows never affect layout, so a large shadow can overlap neighbors or be cut off by an ancestor with overflow: hidden. The outer shadow is also clipped to the area outside the border box, so a translucent card does not show its own shadow through its background.
Why layering works
Split the shadow into jobs. A contact layer has a small offset, a small blur, and the highest alpha; it defines the edge and shows where the card meets the page. An ambient layer has a larger offset, a large blur, a negative spread, and low alpha; it carries the sense of height. A third layer can sit between them when you need a high elevation that still looks crisp.
.card {
border-radius: 12px;
background: white;
box-shadow:
0 1px 2px rgb(15 23 42 / 0.08), /* contact */
0 12px 24px -6px rgb(15 23 42 / 0.14); /* ambient */
}
.dialog {
box-shadow:
0 1px 2px rgb(15 23 42 / 0.08),
0 6px 12px -4px rgb(15 23 42 / 0.10),
0 32px 64px -16px rgb(15 23 42 / 0.28);
}Compare that with one shadow tuned to cover the same area, such as 0 12px 40px rgb(0 0 0 / 0.25). It is too faint at the edge to separate the card from a white page and too strong in the far halo. The layered version can keep each part lighter because each layer only does one job.
Building an elevation scale
Decide what each level is for (resting cards, hovered cards, menus and popovers, dialogs) and define it once. A workable rule: from one level to the next, roughly double the y-offset and blur of the ambient layer, make its spread more negative in proportion, and raise its alpha a little. Keep the contact layer almost constant so every level shares the same edge.
:root {
--shadow-color: 220 40% 15%; /* H S L of a dark blue-gray */
--elevation-1: 0 1px 2px hsl(var(--shadow-color) / 0.08),
0 1px 3px hsl(var(--shadow-color) / 0.06);
--elevation-2: 0 1px 2px hsl(var(--shadow-color) / 0.07),
0 4px 8px -2px hsl(var(--shadow-color) / 0.10);
--elevation-3: 0 2px 4px hsl(var(--shadow-color) / 0.06),
0 12px 24px -6px hsl(var(--shadow-color) / 0.14);
--elevation-4: 0 4px 8px hsl(var(--shadow-color) / 0.06),
0 24px 48px -12px hsl(var(--shadow-color) / 0.22);
}
.card { box-shadow: var(--elevation-1); }
.menu { box-shadow: var(--elevation-3); }
.dialog { box-shadow: var(--elevation-4); }Four or five levels are enough for most interfaces. If you need a sixth, two of the existing levels are probably doing the same job.
Colored shadows
Pure black shadows look gray and dirty on colored backgrounds. Use a dark, desaturated version of the surface's hue instead. That is why the scale above uses a variable: on a warm cream page, change --shadow-color to a dark brown and every level follows.
A glow under a brand-colored button is a different effect. It uses the button's own color at low alpha with a small y-offset. color-mix() derives it from a token so it stays in sync:
.button-primary {
background: var(--brand);
box-shadow:
0 1px 2px rgb(0 0 0 / 0.12),
0 8px 20px -6px color-mix(in oklab, var(--brand) 55%, transparent);
}Keep glows for one or two elements per screen. When every card glows, none of them stands out, and the page looks blurry.
Inset shadows
The inset keyword draws the shadow inside the padding box, as if the element were cut into the page. It suits pressed buttons, wells, and text inputs. A one-pixel inset highlight along the top edge is also a common way to give dark surfaces a lit edge. Inset and outer shadows can share one list.
.input {
box-shadow: inset 0 1px 2px rgb(15 23 42 / 0.08);
}
.button:active {
box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.2);
}
.panel-dark {
background: #1b1b21;
box-shadow:
inset 0 1px 0 rgb(255 255 255 / 0.06), /* lit top edge */
0 1px 2px rgb(0 0 0 / 0.4),
0 16px 32px -12px rgb(0 0 0 / 0.6);
}Shadows in dark mode
A shadow is darkness, and a dark page has little room to get darker, so a shadow tuned for a white page almost disappears on a near-black one. Don't push the alpha until the halo looks like smoke. Use other cues as well: make raised surfaces slightly lighter than the canvas, add the faint inset highlight shown above, or use a one-pixel border in a light color at low alpha. Keep the outer shadows, but raise their alpha and use near-black, because tinted shadows are invisible at that lightness anyway.
:root {
--surface: #ffffff;
--elevation-3: 0 2px 4px rgb(15 23 42 / 0.06), 0 12px 24px -6px rgb(15 23 42 / 0.14);
}
@media (prefers-color-scheme: dark) {
:root {
--surface: #1b1b21; /* lighter than a #09090c canvas */
--elevation-3: inset 0 1px 0 rgb(255 255 255 / 0.06),
0 2px 4px rgb(0 0 0 / 0.5),
0 12px 24px -6px rgb(0 0 0 / 0.6);
}
}Transitions and performance
Browsers can transition between two shadow lists; if one list is shorter, it is padded with transparent shadows. But box-shadow changes are painted, not composited, so every frame of a hover transition repaints the shadow area. On a grid of large cards with big blurs that can drop frames on slower devices. A common fix is to put the raised shadow on a pseudo-element and fade its opacity, which the browser can composite:
.card {
position: relative;
box-shadow: var(--elevation-1);
transition: transform 200ms cubic-bezier(.22, 1, .36, 1);
}
.card::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
box-shadow: var(--elevation-3);
opacity: 0;
transition: opacity 200ms cubic-bezier(.22, 1, .36, 1);
pointer-events: none;
}
.card:hover { transform: translateY(-2px); }
.card:hover::after { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
.card, .card::after { transition: none; }
}Static shadows cost very little. The cost comes from repainting: animated shadows, large blurs on many elements, and shadows inside areas that scroll or animate. If a page feels heavy, check those first in the browser's performance panel before removing shadows everywhere.
Shadows in Tailwind CSS v4
The scale runs shadow-2xs, shadow-xs, shadow-sm, shadow-md, shadow-lg, shadow-xl, and shadow-2xl. shadow-sm through shadow-xl are already two layers each; shadow-lg compiles to 0 10px 15px -3px plus 0 4px 6px -4px, both black at 10% alpha. v4 renamed the small end of the scale: v3's shadow-sm is now shadow-xs, and v3's bare shadow is now shadow-sm. Upgraded projects that kept the old names get slightly heavier small shadows.
<!-- Scale and opacity: /20 sets each layer's alpha to 20% -->
<div class="rounded-xl bg-white shadow-lg/20"></div>
<!-- Colored shadow: the color replaces every layer's color -->
<button class="bg-indigo-600 shadow-lg shadow-indigo-500/40">Save</button>
<!-- Inset shadows are a separate utility and combine with outer shadows -->
<input class="inset-shadow-sm shadow-xs" />
<!-- Your own layered shadow as an arbitrary value: underscores for spaces -->
<div class="shadow-[0_1px_2px_rgb(15_23_42/0.08),0_12px_24px_-6px_rgb(15_23_42/0.14)]"></div>
<!-- Or from a CSS variable -->
<div class="shadow-(--elevation-3)"></div>Two details catch people out. A shadow color class such as shadow-indigo-500 replaces the built-in 10% black entirely, so without an opacity modifier you get a fully opaque indigo shadow. And the color applies to all layers equally, so a colored shadow-lg loses the contrast between its contact and ambient layers. For anything more nuanced, register the scale as theme tokens. Each --shadow-* variable in @theme becomes a utility:
@import "tailwindcss";
@theme {
--shadow-raised: 0 1px 2px rgb(15 23 42 / 0.07), 0 4px 8px -2px rgb(15 23 42 / 0.10);
--shadow-overlay: 0 4px 8px rgb(15 23 42 / 0.06), 0 24px 48px -12px rgb(15 23 42 / 0.22);
}
/* Usage: class="shadow-raised hover:shadow-overlay dark:shadow-none" */Common mistakes
- Using one huge blur at high alpha. It reads as a dark cloud. Split it into a contact and an ambient layer.
- Different light directions on different components, such as a card shadow falling down and a dropdown shadow falling to the right.
- Black shadows on colored or warm backgrounds. Tint them with the background's hue.
- Expecting the shadow to show on an element inside overflow: hidden. The ancestor clips it; add padding to the clipping container or move the shadow outward.
- Relying on a shadow as the only boundary for an input or a card that must be visible to everyone. Low-alpha shadows can disappear on some screens and in forced colors mode. Give inputs a border.
Tuning layers in the GradientDeck generator
The GradientDeck box shadow generator edits one shadow at a time: horizontal and vertical offset (-100 to 100px), blur (0 to 300px), spread (-50 to 100px), a color with alpha, and an inset switch. The preview tile switches between a light and a dark background, which helps when checking the dark-mode advice above. Copy the result as a box-shadow declaration or as a Tailwind shadow-[...] arbitrary value.
To build a layered shadow, tune the contact layer first and copy it, then tune the ambient layer on the same tile. Join the two CSS values with a comma, or join the Tailwind values with a comma inside one shadow-[...] class. The gradient glow examples further down that page are not box-shadow: each one is a blurred gradient element placed behind the card, copied as Tailwind JSX.