What are CSS shadows and which one to use
CSS gives you three main ways to create shadows:
- box-shadow for shadows around boxes (divs, buttons, cards, inputs).
- text-shadow for shadows behind text glyphs (letters).
- filter: drop-shadow() for shadows that follow the actual visible pixels of an element (especially useful for transparent PNGs and SVGs).
A quick rule of thumb:
- If you’re shadowing a card / panel / button → use box-shadow.
- If you’re shadowing text → use text-shadow.
- If you need a shadow that hugs a cut-out image (transparent background) → use filter: drop-shadow().
The shadow mental model: offset, blur, spread, color
Most shadow work is just playing with four “knobs”:
- X offset: move the shadow left/right (negative goes left).
- Y offset: move the shadow up/down (negative goes up).
- Blur: how soft the shadow edges are (bigger = softer).
- Spread (box-shadow only): grow or shrink the shadow before blur.
Then you choose a color (often a semi-transparent black like rgba(0, 0, 0, 0.25)).
CSS box-shadow basics
The classic syntax:
box-shadow: x y blur spread color;
You can also add inset to put the shadow inside the box.
Your first box-shadows
Click the snippets to see how each value changes the feel.
.card {
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.25);
}
.card {
box-shadow: 0px 12px 24px 0px rgba(0, 0, 0, 0.18);
}
.card {
box-shadow: 0px 24px 60px 0px rgba(0, 0, 0, 0.22);
}
.card {
box-shadow: -18px 18px 40px 0px rgba(0, 0, 0, 0.18);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 260px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.card {
width: 320px;
border-radius: 18px;
border: 2px solid #111;
background: #fff;
padding: 18px;
}
.card h4 {
margin: 0 0 8px 0;
font-size: 18px;
}
.card p {
margin: 0;
line-height: 1.4;
opacity: 0.85;
}
Shadow card
box-shadow is for boxes. Simple, powerful, and slightly addictive.
box-shadow interactive sliders
This playground lets you drag the four numeric values. Notice how:
- Bigger Y makes it feel more “lifted”.
- More blur makes it softer.
- Spread can make the shadow feel “wider” without moving it.
.card {
box-shadow: 0px 18px 36px 0px rgba(0, 0, 0, 0.22);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 280px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.card {
width: 340px;
border-radius: 18px;
border: 2px solid #111;
background: #fff;
padding: 18px;
}
.card .row {
display: flex;
gap: 10px;
margin-top: 12px;
}
.badge {
border: 2px solid #111;
border-radius: 999px;
padding: 6px 10px;
font-size: 13px;
background: #fff;
}
Drag the slidersoffsetblurspread
Inset shadows (inside the box)
Add inset to push the shadow inside. This is great for:
- pressed buttons
- input fields
- “carved” or “sunken” UI
.panel {
box-shadow: inset 0px 0px 0px 0px rgba(0, 0, 0, 0.22);
}
.panel {
box-shadow: inset 0px 10px 18px -12px rgba(0, 0, 0, 0.45);
}
.panel {
box-shadow: inset 0px 0px 0px 2px rgba(0, 0, 0, 0.6);
}
.panel {
box-shadow:
inset 0px 12px 18px -16px rgba(0, 0, 0, 0.55),
inset 0px -10px 18px -16px rgba(0, 0, 0, 0.25);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 320px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.panel {
width: 360px;
border-radius: 18px;
border: 2px solid #111;
background: #fff;
padding: 18px;
}
.panel p {
margin: 10px 0 0 0;
opacity: 0.85;
line-height: 1.4;
}
Inset shadowsThey make the element feel like it has depth inside.
Multiple box-shadows (layering)
You can stack multiple shadows by separating them with commas. This is how you get that “real UI” look:
- One small, sharp shadow for contact
- One bigger, softer shadow for lift
- Optional glow or outline for style
.card {
box-shadow: 0px 18px 42px rgba(0, 0, 0, 0.18);
}
.card {
box-shadow:
0px 2px 0px rgba(0, 0, 0, 0.18),
0px 18px 42px rgba(0, 0, 0, 0.14);
}
.card {
box-shadow:
0px 2px 0px rgba(0, 0, 0, 0.16),
0px 16px 40px rgba(0, 0, 0, 0.12),
0px 40px 90px rgba(0, 0, 0, 0.10);
}
.card {
box-shadow:
0px 2px 0px rgba(0, 0, 0, 0.16),
0px 16px 40px rgba(0, 0, 0, 0.12),
0px 0px 0px 3px rgba(17, 17, 17, 0.10);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 320px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.card {
width: 360px;
border-radius: 18px;
border: 2px solid #111;
background: #fff;
padding: 18px;
}
.card .meta {
margin-top: 10px;
display: grid;
gap: 6px;
opacity: 0.85;
}
.pill {
width: fit-content;
border: 2px solid #111;
border-radius: 999px;
padding: 6px 10px;
font-size: 13px;
background: #fff;
}
Layered shadows
box-shadow common mistakes
- Too dark: beginners often use opaque black. Use alpha like rgba(0, 0, 0, 0.15).
- Too blurry without offset: a huge blur at 0 0 looks like a fog halo. Add a little Y offset.
- One shadow only: layering two shadows usually looks more natural than one big one.
Learn even more about box-shadow in the CSS Box Shadow Interactive
Tutorial.
CSS text-shadow basics
text-shadow is like box-shadow but for text glyphs. The syntax is usually:
text-shadow: x y blur color;
Notice there’s no spread for text-shadow.
Simple text-shadow examples
Click around and see how small changes can make text clearer or messier.
.title {
text-shadow: 0px 0px 0px rgba(0, 0, 0, 0.35);
}
.title {
text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.25);
}
.title {
text-shadow: 0px 8px 18px rgba(0, 0, 0, 0.35);
}
.title {
text-shadow: -4px 4px 0px rgba(0, 0, 0, 0.25);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 380px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #0c1020;
}
.block {
width: min(700px, 100%);
border-radius: 18px;
border: 2px solid rgba(255, 255, 255, 0.18);
background: linear-gradient(135deg, rgba(255, 255, 255, 0.40), rgba(255, 255, 255, 0.25));
padding: 22px;
color: #fff;
}
.title {
margin: 0 0 12px 0;
font-size: 46px;
letter-spacing: 0.5px;
}
.sub {
margin: 0;
opacity: 0.85;
line-height: 1.4;
max-width: 60ch;
}
Text shadow
A little shadow can help contrast. Too much shadow can make text harder to read.
text-shadow interactive sliders
Use sliders to learn the “feel” of each number. Keep text shadows subtle for readability.
.title {
text-shadow: 0px 6px 18px rgba(0, 0, 0, 0.45);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 420px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #121826;
}
.hero {
width: min(760px, 100%);
border-radius: 18px;
border: 2px solid rgba(255, 255, 255, 0.14);
background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0.26));
padding: 22px;
color: #fff;
}
.title {
margin: 0;
font-size: 54px;
letter-spacing: 0.5px;
}
.note {
margin: 12px 0 0 0;
opacity: 0.85;
max-width: 65ch;
line-height: 1.4;
}
Slider shadow
Try small blur values first, then increase blur. Big blur is not always better.
Multiple text-shadows: outline and glow
Just like box-shadow, text-shadow can stack with a comma-separated list. Two classic tricks:
- Outline: many tiny shadows around the text (fake stroke).
- Glow: soft blurred shadows for neon vibes.
.word {
text-shadow:
-2px 0px 0px rgba(0, 0, 0, 0.55),
2px 0px 0px rgba(0, 0, 0, 0.55),
0px -2px 0px rgba(0, 0, 0, 0.55),
0px 2px 0px rgba(0, 0, 0, 0.55);
}
.word {
text-shadow:
0px 0px 10px rgba(255, 255, 255, 0.55),
0px 0px 24px rgba(255, 255, 255, 0.28);
}
.word {
text-shadow:
0px 2px 0px rgba(0, 0, 0, 0.25),
0px 18px 22px rgba(0, 0, 0, 0.35);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 420px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: linear-gradient(135deg, #999999, #2b1d3a);
}
.word {
margin: 0;
font-size: 64px;
font-weight: 700;
letter-spacing: 1px;
color: #fff;
}
.hint {
margin: 14px 0 0 0;
opacity: 0.85;
max-width: 70ch;
line-height: 1.4;
color: rgba(255, 255, 255, 0.9);
}
SHADOW
Multiple text-shadows can fake an outline or create a glow.
Learn more about text-shadow in the CSS Text Shadow Interactive
Tutorial.
CSS filter: drop-shadow() basics
drop-shadow() is part of the filter property. It creates a shadow based on the element’s rendered shape, not its rectangle.
That means it can shadow the visible pixels of:
- transparent PNGs
- SVGs
- elements with transparency (depending on the content)
Syntax:
filter: drop-shadow(x y blur color);
There’s no spread value in drop-shadow().
drop-shadow vs box-shadow on transparent images
This is the big “aha” moment. When you use box-shadow on an image element, you’re shadowing its box (rectangle). With drop-shadow(), you’re shadowing the actual cut-out shape.
.figure img {
box-shadow: 0px 22px 38px rgba(0, 0, 0, 0.28);
}
.figure img {
filter: drop-shadow(0px 22px 24px rgba(0, 0, 0, 0.35));
}
.figure img {
filter: drop-shadow(-12px 18px 22px rgba(0, 0, 0, 0.30));
}
.figure img {
filter:
drop-shadow(0px 18px 20px rgba(0, 0, 0, 0.28))
drop-shadow(0px 4px 0px rgba(0, 0, 0, 0.12));
}
*, ::before, ::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 500px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 18px;
width: min(860px, 100%);
}
.figure {
border: 2px solid #111;
border-radius: 18px;
background: #fff;
padding: 14px;
display: grid;
gap: 10px;
justify-items: center;
}
.figure h4 {
margin: 0;
font-size: 14px;
opacity: 0.85;
}
.figure img {
width: 210px;
height: auto;
display: block;
}
.small {
opacity: 0.75;
font-size: 13px;
text-align: center;
max-width: 40ch;
line-height: 1.35;
}
Transparent PNG
![]()
Try box-shadow vs drop-shadow. One follows the box, one follows the pixels.
Transparent PNG
![]()
drop-shadow() is usually the “correct” shadow for cut-outs.
drop-shadow interactive sliders
Same idea as before: offsets + blur. Keep it subtle and slightly offset for natural “lift”.
.figure img {
filter: drop-shadow(0px 18px 22px rgba(0, 0, 0, 0.32));
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 520px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.figure {
width: min(860px, 100%);
border: 2px solid #111;
border-radius: 18px;
background: #fff;
padding: 18px;
display: grid;
gap: 14px;
justify-items: center;
}
.figure img {
width: 320px;
height: auto;
display: block;
}
.caption {
text-align: center;
max-width: 70ch;
opacity: 0.85;
line-height: 1.4;
margin: 0;
}
![]()
Drag X, Y, and blur. You’re editing the drop-shadow() values inside filter.
Multiple drop-shadows and filter chains
You can stack multiple drop-shadows by listing multiple functions in filter. This is handy when you want a softer “lift” shadow plus a tiny “contact” shadow.
You can also combine drop-shadow with other filter functions. Just remember: filters can be more expensive than box-shadows, so don’t slap them on 300 items in a scrolling list and then blame your laptop fan.
.art {
filter:
drop-shadow(0px 18px 22px rgba(0, 0, 0, 0.26))
drop-shadow(0px 4px 0px rgba(0, 0, 0, 0.10));
}
.art {
filter:
drop-shadow(0px 18px 22px rgba(0, 0, 0, 0.26))
drop-shadow(0px 4px 0px rgba(0, 0, 0, 0.10))
brightness(1.05);
}
.art {
filter:
drop-shadow(-12px 18px 22px rgba(0, 0, 0, 0.28))
drop-shadow(0px 4px 0px rgba(0, 0, 0, 0.10))
contrast(1.06);
}
*,
::before,
::after {
box-sizing: border-box;
}
.demo-wrap {
min-height: 540px;
display: grid;
place-items: center;
padding: 24px;
font-family: ui-monospace, SFMono-Regular, monospace;
background: #f6f7fb;
}
.frame {
width: min(920px, 100%);
border: 2px solid #111;
border-radius: 18px;
background: #fff;
padding: 18px;
display: grid;
gap: 14px;
justify-items: center;
}
.row {
display: flex;
gap: 24px;
flex-wrap: wrap;
justify-content: center;
}
.art {
width: 260px;
height: auto;
display: block;
}
.note {
margin: 0;
opacity: 0.85;
line-height: 1.4;
max-width: 80ch;
text-align: center;
}
![]()
![]()
filter can chain multiple drop-shadows and other effects. Use with taste (and performance in mind).
Learn more about filter: drop-shadow() in the CSS Drop Shadow Interactive
Tutorial.
Shadow quality checklist and practical tips
- Use transparency: shadows usually look best with alpha (not solid black).
- Prefer Y offset over X for natural light: most UIs assume light from above.
- Layer for realism: try two shadows (contact + lift) instead of one big blob.
- Keep text readable: avoid huge blur on body text; use subtle shadows or none.
- Use drop-shadow for cut-outs: it follows the pixels, not the rectangle.
- Watch performance: heavy filters on many elements can be costly.
Common shadow debugging
My box-shadow looks like a halo
You probably have 0px 0px offsets with a large blur. Add a little Y offset (like 0px 12px) and reduce opacity.
My shadow is clipped or cut off
The parent might have overflow: hidden, or the element is inside a container that clips effects. For drop-shadow, clipping can also happen depending on layout. Try removing overflow clipping or adding padding around the element.
My drop-shadow is not working
Make sure you’re using filter: drop-shadow(...) (not box-shadow), and that the element actually has visible pixels. Also check if another rule overrides filter.
Wrap-up: CSS shadows (you now have superpowers)
If you remember only one thing, remember this: box-shadow is for boxes, text-shadow is for text, and drop-shadow() is for the actual visible shape. Combine subtle values with layering, and your UI will instantly feel more “real”.
