text-shadow is one of the oldest decorative properties in CSS and still one of the most versatile. With a single value it lifts a heading slightly off the page. With a stack of values it turns plain text into glowing neon tubes, chunky 3D lettering, outlined poster type or a subtle debossed label. It also has a practical job: keeping white text legible on top of photos.
This guide explains the syntax, how multiple layers combine, the recipes behind the popular effects, and where text shadows help or hurt readability.
The syntax
A text shadow has up to four parts:
text-shadow: offset-x offset-y blur-radius color;
- offset-x: horizontal shift. Positive moves right, negative moves left.
- offset-y: vertical shift. Positive moves down, negative moves up.
- blur-radius: optional, defaults to 0 (a hard copy of the text). Larger values spread and soften the shadow. Negative values are not allowed.
- color: optional; if omitted, the text's own colour is used. Use
rgba()or a hex with alpha for transparency.
.heading {
color: #1e293b;
text-shadow: 1px 2px 3px rgba(0, 0, 0, 0.25);
}
Unlike box-shadow, text-shadow has no spread value and no inset keyword. The shadow follows the exact outline of each glyph.
Stacking multiple shadows
Separate shadows with commas to layer them. The first shadow is drawn on top, and each following one sits behind the previous. This order matters: a sharp dark layer listed after a soft glow ends up behind it.
All the classic effects are simply different stacks.
Neon glow
Several shadows with zero offset and increasing blur, usually a tight white core and wider coloured halos:
.neon {
color: #ffffff;
text-shadow:
0 0 4px #ffffff,
0 0 10px #22d3ee,
0 0 20px #22d3ee,
0 0 40px #0ea5e9;
}
It only looks like neon on a dark background. On white, the glow disappears.
3D extruded text
Hard shadows (zero blur), each offset one pixel further, build up a solid "side" to the letters. A final soft shadow grounds it:
.three-d {
color: #f8fafc;
text-shadow:
1px 1px 0 #1e3a8a,
2px 2px 0 #1e3a8a,
3px 3px 0 #1e3a8a,
4px 4px 0 #1e3a8a,
5px 5px 0 #1e3a8a,
6px 8px 10px rgba(0, 0, 0, 0.35);
}
More steps give deeper extrusion. Change the direction of the offsets to change where the light seems to come from.
Outline
Four hard shadows offset diagonally by 1px draw a thin border around each letter:
.outline {
color: #ffffff;
text-shadow:
-1px -1px 0 #0f172a,
1px -1px 0 #0f172a,
-1px 1px 0 #0f172a,
1px 1px 0 #0f172a;
}
This works for thin outlines. For thicker ones, gaps appear at the corners; -webkit-text-stroke (supported in current browsers despite the prefix) draws a true stroke, though it eats into the letter shape, which the paint-order property can help with.
Letterpress and retro
A 1px light shadow below slightly muted text on a similar background looks pressed into the surface. Two or more offset hard shadows in contrasting colours give a retro, misregistered-print look.
Build a shadow stack visually
The Text Shadow Generator lets you edit each layer and see the result on your own text.
- Open the Text Shadow Generator. Start from a preset if one is close: Subtle, Neon, 3D, Outline, Retro, Glow or Letterpress. Presets also set suitable text and background colours.
- Select a layer in the Shadow layers list, then adjust Horizontal offset (X), Vertical offset (Y), Blur radius, Opacity and Shadow colour.
- Click Add layer to stack another shadow, or remove one with its delete button. The layer at the top of the list is drawn on top.
- Type your own Preview text, set the Text colour and Background, and change Font size (preview) to see how the effect scales.
- Copy the CSS, which includes the
colorand the fulltext-shadowstack, one layer per line.
Shadows for readability
Decorative effects aside, the most useful text shadow is often the least visible. White headings over photographs or video frequently fail contrast in bright areas. A soft, dark shadow creates a halo that keeps edges readable:
.hero-title {
color: #ffffff;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6), 0 0 12px rgba(0, 0, 0, 0.35);
}
That helps, but it is not a guarantee. Contrast guidelines are judged against the actual background, and a shadow only partly changes it. For important text, combine a shadow with a semi-transparent overlay on the image, then check the result in the colour contrast checker. The WCAG contrast guide explains the thresholds.
Pitfalls
Too many layers on body text
Heavy effects make running text harder to read, especially at small sizes. Keep neon, 3D and outline effects to large display type: headings, logos, banners.
Performance with animated shadows
Animating large blurred text shadows forces repainting every frame. A glow that pulses is fine for one heading; applied to dozens of elements it can slow scrolling. If you want a pulsing glow, animating opacity on a duplicate layer is cheaper. The CSS animation generator helps with the keyframes.
Shadows get cut off
A parent with overflow: hidden, or tight line-height, can clip large offsets and blurs. Add padding or reduce the spread.
Copying text with effects
Shadows are purely visual; screen readers and copy-paste see normal text. That is an advantage over "fancy text" made from Unicode lookalike characters, which screen readers may read letter by letter. If you need styled text for places where CSS is not available, such as social bios, the fancy text generator produces Unicode styles, but use them sparingly for the same accessibility reason.
text-shadow versus box-shadow
text-shadow follows glyph shapes; box-shadow follows the element's rectangular (or rounded) box and supports spread and inset. For cards, buttons and panels, use the box shadow generator. For letters, use text-shadow. To give an irregular shape such as an icon a shadow that follows its outline, filter: drop-shadow() is the third option.
Frequently asked questions
What are the values in text-shadow?
Horizontal offset, vertical offset, optional blur radius and optional colour, in that order. Separate multiple shadows with commas.
How do I make neon text in CSS?
Use light text on a dark background and stack several shadows with zero offset and increasing blur, starting with a tight white or pale layer and adding wider coloured glows.
Which text-shadow layer is on top?
The first one in the list. Later shadows are painted behind earlier ones.
Can text-shadow create an outline?
Yes, four 1px hard shadows offset in each diagonal direction give a thin outline. For thicker, cleaner outlines, consider -webkit-text-stroke.
Does text-shadow affect accessibility?
It does not change what assistive technology reads, but it affects visual legibility. Subtle shadows can improve contrast over images; heavy effects on small text can make it harder to read.