Box Shadow Cheatsheet: Interactive Visual Guide
October 15, 2026 | Cheatsheet | CSS
By Syed · Frontend Engineer & Creator of UITweak
Shadows are one of the fastest ways to add depth to a UI, but the values are hard to picture from code alone. Every section below is interactive: drag a slider, pick a preset, watch the shadow change, then copy the CSS.
Interactive shadow builder
Dragging the offsets moves the shadow's blurred copy of the box: positive x pushes it right, positive y pushes it down, following the direction light would fall across the surface. Blur spreads the shadow's edge over more pixels, which costs more paint work the larger it gets, while spread grows or shrinks the shadow's solid core before any blurring happens. inset draws that same shape inside the border box instead of outside it.
.card {
box-shadow: 0px 12px 24px 0px rgba(30, 41, 59, 0.25);
}box-shadow syntax order
Only the two offsets are required; blur defaults to zero, spread to zero, and color to the element's own text color. The inset keyword may sit anywhere in the declaration, before or after the lengths and the color. Remember that currentColor default: omitting the color on dark text produces a dark shadow, which is why writing the color explicitly is the safer habit.
Click each slot to see what it does:
offset-y
Required. Moves the shadow vertically. Negative values push it up, positive values push it down. A positive offset-y is the classic drop shadow.
box-shadow: offset-x offset-y blur-radius spread-radius color inset;
/* only offset-x and offset-y are required */
.card {
box-shadow: 0 12px 24px rgba(30, 41, 59, 0.25);
}Layered shadows
Comma-separated shadows stack in paint order with the first listed on top, so a tight dark shadow can sit over a wide soft one without muddying it. Layering mimics how real light wraps an object: a small sharp contact shadow near the edge plus a large faint ambient shadow beneath it. This is why layered presets look photographic while a single large blur reads as a smudge.
single shadow
layered shadows
Three layers: a tight contact shadow, a mid-range shadow, and a wide ambient shadow. This is the standard recipe for a card that feels like it floats.
.card {
box-shadow:
0 1px 2px rgba(16, 24, 40, 0.06),
0 4px 8px -2px rgba(16, 24, 40, 0.10),
0 16px 32px -12px rgba(16, 24, 40, 0.18);
}Tailwind shadow utilities
Each Tailwind utility maps to a fixed, curated shadow stack with baked-in color and opacity, so shadow-lg renders the same pixels wherever you use it. That consistency is the point, but it also means you cannot tune one value without leaving the scale entirely. For anything between steps, an arbitrary value like shadow-[0_20px_40px_-12px_rgba(0,0,0,0.35)] drops straight through to raw CSS.
shadow-sm0 1px 2px 0 rgb(0 0 0 / 0.05)
shadow0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)
shadow-md0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)
shadow-lg0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)
shadow-xl0 20px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.08)
shadow-2xl0 25px 50px -12px rgb(0 0 0 / 0.25)
shadow-innerinset 0 2px 4px 0 rgb(0 0 0 / 0.05)
shadow-none0 0 #0000
<!-- any custom shadow, one class -->
<div class="shadow-[0_20px_40px_-12px_rgba(0,0,0,0.35)]">
custom shadow
</div>
<!-- colored shadow: tint it with any color -->
<div class="shadow-lg shadow-indigo-500/40">
indigo-tinted shadow
</div>Common recipes
The three recipes on the page each lean on a different shadow behavior: the card hover swaps one shadow for a deeper one, which repaints on every frame of the transition; the focus ring uses box-shadow instead of border so the ring adds no layout shift; and text-shadow paints per glyph, which is why it stays crisp on large display type where a blurred box shadow would look muddy.
1. Card elevation on hover
Hover me
shadow-md to shadow-2xl
2. Focus ring shadow
3. Text shadow
Glowing headline
Tailwind has no text-shadow utility. Use an arbitrary property instead:
<!-- card lift on hover -->
<div class="shadow-md hover:shadow-2xl transition-shadow duration-300">
hover me
</div>
<!-- focus ring without outline -->
<input class="outline-none focus:shadow-[0_0_0_4px_rgba(99,102,241,0.35)]" />
<!-- text-shadow via arbitrary property -->
<p class="[text-shadow:0_2px_12px_rgb(0_0_0/0.6)]">
glowing headline
</p>Want layered shadows without the math? Try our free Box Shadow Generator with live preview and one-click code export.
Common Production Bugs & Fixes
Animating box-shadow tanks the frame rate
Hovering a card that transitions between two large blurred shadows stutters on low-end devices. Every frame of that transition repaints the shadow from scratch, and blur radius is one of the most expensive paint operations because each pixel samples a wide neighborhood. Keep shadows static and animate transform or opacity instead; when the shadow itself must change, fade a pseudo-element that carries the second shadow.
.card { position: relative; transition: transform 0.25s ease-out; }
.card::after {
content: ""; position: absolute; inset: 0; border-radius: inherit;
box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.35);
opacity: 0; transition: opacity 0.25s ease-out;
}
.card:hover { transform: translateY(-4px); }
.card:hover::after { opacity: 1; }An inset shadow disappears behind the content
You add an inset shadow for an inner glow, but the card's image or a solid child covers it completely. Inset shadows paint above the element's background yet below its content, so any opaque child or text sits on top of them. Put the inset shadow on a positioned pseudo-element layered above the content, with pointer-events: none so it never blocks clicks.
.frame { position: relative; }
.frame::before {
content: ""; position: absolute; inset: 0; border-radius: inherit;
box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
pointer-events: none;
}The shadow vanishes in dark mode
A card shadow that reads perfectly on a light page becomes invisible on a dark background. A black shadow at low opacity has almost no contrast against a near-black surface, because there is no darker tone left to show. Dark-mode shadows need a lighter tint at low opacity, or a larger softer shadow that reads as glow rather than occlusion, tuned separately in your dark theme.
.card { box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.25); }
.dark .card { box-shadow: 0 12px 40px -8px rgba(255, 255, 255, 0.08); }Shadows get clipped by an overflow: hidden ancestor
A dropdown or tooltip shadow is sliced off flat at the edge of its container. Shadows paint outside the border box, and any ancestor with overflow other than visible clips everything outside its padding box, shadow included. Move the overflow: hidden to an inner wrapper so the clipping boundary sits inside the shadowed box instead of outside it.
/* before: .menu { overflow: hidden; box-shadow: ... } clips its own shadow */
/* after: clip the inner content, keep the shadow on the outer box */
.menu { box-shadow: 0 18px 44px -6px rgba(0, 0, 0, 0.3); }
.menu-inner { overflow: hidden; border-radius: 12px; }Real-World Recipes
Floating glass panel
Layer two shadows, a tight one for contact and a wide faint one for atmosphere, over a translucent background with backdrop-filter: blur(). Keep the shadow color cool and desaturated so it reads as depth rather than dirt. Because the panel floats, add a small translateY lift on hover but leave the shadows static so the transition stays cheap.
.glass {
background: rgba(255, 255, 255, 0.6);
backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 20px;
box-shadow:
0 2px 6px rgba(30, 41, 59, 0.12),
0 24px 48px -12px rgba(30, 41, 59, 0.25);
transition: transform 0.25s ease-out;
}
.glass:hover { transform: translateY(-4px); }Pressed button with inset shadows
Pair a dark inset shadow on the top edge with a light inset shadow on the bottom edge to fake a concave surface. On :active, deepen both insets slightly and nudge the label down one pixel with translateY for tactile feedback. Use this sparingly: full-page neumorphism washes out contrast, but one pressed control reads clearly.
.btn-pressed {
border-radius: 12px;
background: #e2e8f0;
box-shadow:
inset 0 2px 4px rgba(15, 23, 42, 0.18),
inset 0 -2px 4px rgba(255, 255, 255, 0.7);
transition: box-shadow 0.15s ease-out, transform 0.15s ease-out;
}
.btn-pressed:active {
box-shadow:
inset 0 3px 8px rgba(15, 23, 42, 0.28),
inset 0 -1px 2px rgba(255, 255, 255, 0.5);
transform: translateY(1px);
}One-sided shadow for a sticky header
Offset the shadow downward and use a negative spread about equal to the blur to pull the other three sides back under the box, so the shadow escapes only below the element. On a sticky nav this gives separation from the scrolling content without a hard border line. The shadow is static, so it costs one paint no matter how far the user scrolls.
.site-header {
position: sticky; top: 0; z-index: 50;
background: #ffffff;
box-shadow: 0 12px 16px -12px rgba(15, 23, 42, 0.25);
}FAQ
Does box-shadow change layout or the clickable area?
No. Shadows are purely visual and add nothing to the box model, so they never move siblings and never extend hit-testing. One exception: a very large shadow can enlarge a scroll container's scrollable overflow area, producing scrollbars you did not expect.
Why does box-shadow follow border-radius but filter: drop-shadow() follow the image shape?
box-shadow is drawn from the border box, so it inherits the element's rounded corners and ignores transparent regions of a PNG inside it. drop-shadow() is a filter applied to the rendered pixels, so it traces the actual alpha silhouette, including holes and transparent image areas. Use box-shadow for boxes and drop-shadow() for irregular shapes.
How do I get a shadow on only one side?
Offset the shadow toward that side and use a negative spread roughly equal to the blur to pull the other three sides back under the box. box-shadow: 0 12px 12px -12px rgba(0, 0, 0, 0.35) leaves a soft shadow only beneath the element, because the negative spread contracts the shadow's footprint until only the downward offset escapes.
Can inset shadows use spread and color like outer ones?
Yes, the full value set works the same: offsets shift the shadow, blur softens it, a positive spread expands how much of the interior it covers, and color tints it. A large positive spread on an inset shadow fills the whole interior, which is a cheap way to paint an inner vignette without adding an extra element.
More cheatsheets:
- Flexbox Cheatsheet: Interactive Visual Guide
- CSS Grid Cheatsheet: Interactive Visual Guide
- CSS Animation Cheatsheet: Interactive Visual Guide
- Border Radius Cheatsheet: Interactive Visual Guide
- CSS Transitions Cheatsheet: Interactive Visual Guide
- CSS Gradients Cheatsheet: Interactive Visual Guide
- CSS Transforms Cheatsheet: Interactive Visual Guide
- CSS Position Cheatsheet: Interactive Visual Guide