CSS Text Shadow Generator: Techniques Beyond the Basic Drop Shadow
A CSS text shadow generator builds the text-shadow value for you: horizontal offset, vertical offset, blur radius and colour, with as many layers as you need. The property has no spread and no inset keyword, so every advanced look, from neon to letterpress, comes from stacking layers. Here is how to read the values, design legible effects, and avoid the usual traps.
Step-by-Step Workflow
- Type your real heading into the preview, not placeholder text. Shadows behave differently on thin and heavy fonts.
- Start with a single layer: 2px, 2px, 4px, low-opacity black.
- Add a second layer only when the first can't do the job. Change colour, not just position.
- Check the result at the real font size on the real background colour.
- Copy the declaration. If the layers get long, put the value in a CSS custom property so you can reuse it.
What Each Value Does
| Position | Meaning | Notes |
|---|
| 1st length | Horizontal offset | Positive moves right |
| 2nd length | Vertical offset | Positive moves down |
| 3rd length (optional) | Blur radius | Defaults to 0 (hard edge); can't be negative |
| Colour (optional) | Shadow colour | Defaults to currentColor |
Layers are separated by commas, and the first one is painted on top. That order matters when you stack a crisp outline over a soft glow. The full definition is in the CSS Text Decoration Module and on MDN.
Recipes You Can Copy
Readable text on a photo
.hero-title {
color: #fff;
text-shadow: 0 1px 2px rgba(0,0,0,.6),
0 4px 16px rgba(0,0,0,.35);
}
A tight dark layer separates the letter edges, and a wide soft layer darkens the area behind them. Together they keep white text readable on bright images.
Four-way outline
.outlined {
color: #ffd43b;
text-shadow: -1px -1px 0 #222, 1px -1px 0 #222,
-1px 1px 0 #222, 1px 1px 0 #222;
}
This fakes a stroke. For real outlines, -webkit-text-stroke exists but it's centred on the glyph edge, which thins the letters.
Neon sign
.neon {
color: #fff;
text-shadow: 0 0 4px #fff,
0 0 10px #ff2e97,
0 0 24px #ff2e97,
0 0 48px #ff2e97;
}
White core, then the same colour at growing blur. Use it on a dark background only.
Letterpress (debossed)
.letterpress {
color: #5b6573;
background: #cbd2db;
text-shadow: 0 1px 0 rgba(255,255,255,.7);
}
The tiny light shadow below the text looks like a lit edge. Keep it at 1px.
Long 3D extrusion
.extruded {
color: #fff;
text-shadow: 1px 1px 0 #c0392b, 2px 2px 0 #c0392b,
3px 3px 0 #c0392b, 4px 4px 0 #c0392b,
5px 5px 8px rgba(0,0,0,.4);
}
Each step adds one pixel of depth with zero blur. Tools like the generator spare you from typing all the steps by hand.
Text Shadow vs Filter Drop Shadow
Both can shadow glyphs, but they behave differently. text-shadow follows each letter and any text decoration. filter: drop-shadow() follows the alpha of the whole element, so it also shadows backgrounds, borders and icons. Use text-shadow for text-only needs. Switch to drop-shadow when the text sits in a transparent PNG, SVG or background-clip: text gradient, because text-shadow shows through transparent text fill in an ugly way. For gradient-filled text, see the CSS gradient generator for the fill and apply the shadow on a wrapper with a filter.
Accessibility and Legibility
- A shadow does not count as background when contrast is calculated. Test the text colour against the actual background using WCAG 1.4.3 (4.5:1 body, 3:1 large). A shadow can improve real readability, but don't count on it to pass an audit.
- Glows reduce legibility. Heavy blur makes letter edges mushy, and it hurts people with dyslexia or low vision. Keep neon for short display text.
- Skip shadows on body copy. They add visual noise at 16px.
- In Windows forced-colors mode, text-shadow is turned off, so don't let a design depend on it for meaning.
Performance
Shadows on a few headings cost nothing noticeable. Problems appear with 20-layer extrusions on large text that animates, or glows on hundreds of list items. Painting a blurred shadow means a blur pass per layer. Keep layers under about six on animated text, and animate colour or opacity rather than blur radius where possible.
Common Mistakes
- Using a spread value.
text-shadow: 1px 1px 2px 3px red is invalid. Only box-shadow has spread, and the whole declaration is dropped. - Pure black at full opacity. It looks harsh. Use
rgba(0,0,0,.3) to .5. - Same colour as the text. The default colour is
currentColor, so omitting the colour on light text gives a pale, pointless shadow. - Clipped glow. A large blur may be cut by
overflow: hidden on the parent. Add padding to give it room. - Mismatched layer counts in transitions. Animating between different numbers of layers can snap, so pad the shorter list with transparent layers (
0 0 0 transparent).
Where It Helps
Good fits: hero headings over images, game or event posters, buttons with embossed labels, and retro or neon branding. Poor fits: paragraphs, form labels, small UI text. If the shadow concerns a card or button rather than words, the box shadow generator is the right tool. You can try combined effects quickly in the HTML live preview.
Reusable Shadows With Custom Properties and Hover Effects
Long layered values are painful to repeat. Store them once:
:root {
--text-glow: 0 0 6px #22d3ee, 0 0 18px #22d3ee, 0 0 40px #0891b2;
--text-lift: 0 1px 2px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.3);
}
.logo { text-shadow: var(--text-glow); }
.banner { text-shadow: var(--text-lift); }
For a hover effect, keep the same number of layers in both states and change only colour or offset, so the browser can interpolate them:
.link {
text-shadow: 0 0 0 transparent, 0 0 0 transparent;
transition: text-shadow .25s ease;
}
.link:hover {
text-shadow: 0 2px 6px rgba(37, 99, 235, .6), 0 0 16px rgba(37, 99, 235, .4);
}
Notice that the resting state lists two transparent layers, matching the two in the hover state. If you wrote only none, the transition would still run in modern browsers, but matching layer lists is the safest way to avoid jumps.
When you use the glow on a dark theme, also reduce it for users who ask for less motion if it pulses. A static glow is fine; a flickering one should be disabled inside @media (prefers-reduced-motion: reduce). The WCAG pause, stop, hide guidance applies to anything that moves for more than five seconds.
More Text Shadow Questions
Can I add a text shadow to only part of a word?
Wrap that part in a <span> and apply the style to the span. The shadow follows glyphs in the span only.
Why is my shadow showing through gradient text?
When text fill is transparent (-webkit-text-fill-color: transparent), the shadow is painted behind it and shows through the glyphs. Put the shadow on a parent with filter: drop-shadow() instead.
Does text-shadow work on pseudo-elements?
Yes, on ::before and ::after, and also on ::first-line and ::first-letter.
What is the best shadow for white text on a light image?
Use two layers: a small, dark, low-blur layer for edge definition and a wide, faint dark layer to dim the area behind. If it still isn't readable, add a semi-transparent overlay to the image.
Is text-shadow supported everywhere?
Yes. It has been supported across all major browsers for many years; confirm on caniuse.