Educational guide to text-shadow
Shadows that follow the letters
See what casts a text shadow, how layers stack, and what stays legible when you remove the effect.
Mental model
text-shadow follows the painted shape of the text and its decorations, such as underlines. The shadow is drawn behind the glyphs and leaves their dimensions and line spacing intact.
- X and Y offsets
The first two values move the shadow along the physical axes. Positive X moves it right and positive Y moves it down. Negative values reverse the direction.
- Blur radius
The third length softens the edge. Omitting it or setting it to zero gives a sharp edge. The radius accepts zero and positive lengths.
- Shadow color
Pick an explicit color to control the effect. A color with alpha lets some of the paint behind it show through.
Glyphs versus box
Use text-shadow to follow the letters and box-shadow to follow the surface.
The same letters and the same offset
text-shadow
Aa
box-shadow
Aa
Both effects add paint without reserving layout space. If a shadow reaches another element, adjust the offset or the actual spacing between boxes.
Layers and blur
Separate layers with commas. The first shadow is painted in front of the others, and all of them sit behind the text. You can soften each layer independently.
The same two layers with sharp or soft edges
Sharp edges
Depth
Soft edges
Depth
To add depth to a heading, start with a close shadow and add a softer second layer. Read the result at its actual size, since a strong shadow can fill the space between letters.
Legibility with or without a shadow
Choose a text and background color pair that keeps its contrast with text-shadow: none. A shadow can help distinguish edges, but adding one does not guarantee contrast.
The same notice on an opaque background
Without a shadow
Registration is open
With a shadow
Registration is open
WCAG 2.2 AA requires 4.5:1 for normal text and 3:1 for large text. If a photo, gradient, or theme changes the background, measure contrast against the least favorable area behind the letters. An opaque background can keep it consistent.
Common pitfalls
The shadow also appears on a subheading
- Expected result
- The shadow appears on the heading alone.
- Cause
- text-shadow inherits when you declare it on the container.
- Solution
- Target the heading directly or use text-shadow: none on the descendant.
The letters lose definition
- Expected result
- The strokes and spaces between letters remain distinct.
- Cause
- A strong blur or too many layers fill the gaps.
- Solution
- Reduce opacity, the blur radius, or the number of layers and read the text again.
Support and compatibility
The basic text-shadow syntax is Baseline Widely Available. Spread and the inset value appear in the CSS Text Decoration Level 4 draft. Check those extensions separately.
In forced colors, the browser applies the user’s palette and removes text shadows. Use words or visible markers when text needs to communicate a state.