CSS Text Shadow: From Subtle Readability Fixes to Neon and 3D Effects
text-shadow is one of the oldest decorative properties in CSS. It first appeared in the CSS2 specification in 1998, was dropped from CSS 2.1 because almost no browser supported it, and came back in CSS3. Today it works everywhere and does far more than add a drop shadow. With a few stacked values you can make text glow, pop out in 3D or get an outline, all while staying real, selectable, searchable text.
The syntax
text-shadow: offset-x offset-y blur-radius color;Unlike box-shadow, there is no spread value and no inset. Offsets move the shadow right and down; the blur softens it. Separate multiple shadows with commas, and the first one is drawn on top.
Four effects, four techniques
| Effect | Technique | Example |
|---|---|---|
| Soft drop shadow | One shadow, small offset, medium blur, low opacity | 0 2px 8px rgb(0 0 0 / 0.25) |
| Neon glow | Several shadows with zero offset and increasing blur in the same bright color | 0 0 4px #fff, 0 0 10px #0ff, 0 0 20px #0ff, 0 0 40px #0ff |
| Retro 3D / extruded | Many hard shadows (no blur), each 1px further | 1px 1px 0 #c8a97e, 2px 2px 0 #c8a97e, 3px 3px 0 #c8a97e … |
| Simple outline | Four 1px hard shadows in each diagonal direction | -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000 |
The text shadow generator above has presets for each, so you can see how the values combine before tweaking them.
Why neon needs several layers
A single blurred shadow looks like a smudge. Real neon tubes have a bright core and a glow that fades gradually into the surrounding air. Stacking shadows with blur values that double each time (for example 5, 10, 20 and 40px) reproduces that falloff. You need a dark background: glow is the difference between a light color and its surroundings, and on white there is nothing to glow against.
Why 3D needs many hard shadows
One offset shadow looks like a flat duplicate behind the text. Many shadows offset one pixel at a time fill in the gap, creating a solid extruded side. Making the later shadows slightly darker adds a hint of shading. For long extrusions this gets verbose, and each shadow adds rendering work, so keep it to headings.
text-shadow versus -webkit-text-stroke for outlines
| Approach | Pros | Cons |
|---|---|---|
| Four (or eight) 1px text shadows | Works everywhere, outline sits outside the letters | Corners can look jagged at thicker widths |
-webkit-text-stroke: 2px #000 | Clean, even stroke | Stroke is centered on the glyph edge, eating into thin letters; prefixed, though supported in all major browsers |
paint-order: stroke fill with text-stroke | Stroke drawn behind fill for clean results | Support for HTML text is newer and less consistent |
| SVG text with stroke | Full control | Not regular HTML text |
For thin outlines on headings, shadows are reliable. For thick outlined “hollow” type, text-stroke usually looks better.
The useful case: text over images
The most practical use of text-shadow is helping white text stay readable over photographs. A soft, dark shadow such as 0 1px 3px rgb(0 0 0 / 0.5) creates a thin dark halo that separates letters from busy or bright backgrounds.
But it is not a guarantee. WCAG contrast is measured between the text color and the background behind it, and shadows aren’t part of that calculation. On a very bright sky, a white headline with a shadow can still be hard to read. More reliable options:
- a gradient overlay on the image, darker where the text sits (see our CSS gradients guide),
- a semi-transparent panel behind the text,
- choosing or cropping the photo so text sits on a calm area.
Use the shadow as an extra layer of safety on top of one of these, and check the final result with a contrast checker.
When text-shadow hurts
Body text. Even soft shadows reduce the crispness of letter edges. At 16px, this makes text look blurry, especially on standard-density screens. Keep paragraphs shadow-free.
Light text on light backgrounds. A shadow can make low-contrast text look readable to the designer while still failing for users with low vision.
Overused effects. Neon and 3D effects lose their impact when they appear on every heading. Use them for one hero title or a logo-style headline.
Performance on huge blur values. Large blurs on lots of text, especially if animated, cost rendering time. Animating text-shadow causes repaints on every frame; animate opacity on a duplicate layer if you need a pulsing glow.
Shadowed text is still real text
Text with shadows remains real text: screen readers read it, users can select and translate it, and search engines index it. That is a big advantage over images of styled text. Just remember that text-shadow is invisible to anyone using Windows High Contrast (forced colors) mode, where browsers remove shadows and replace colors, so the text must work without the effect.
Pairing with other effects
- Gradient text can’t use
text-shadowdirectly, because the text fill is transparent and the shadow shows through. Usefilter: drop-shadow()on the element instead. See our gradient text generator. - Glow buttons combine a
box-shadowglow on the button with a smallertext-shadowon the label. - Pressed or engraved text uses a 1px light shadow below dark text (or a dark shadow above light text) to suggest letters cut into the surface.