Skip to content
Tutorials Center
My learning

Topics

Lesson 46 of 139 ยท Text and Fonts

Text Shadows

Add depth, glows and outlines to text with CSS text-shadow, layer multiple shadows, and use subtle shadows to keep text readable on photos and busy backgrounds.

text-shadow paints one or more shadows behind the letters of a piece of text. Unlike box-shadow, which follows the rectangle of an element, a text shadow follows the exact shape of every glyph: each curve of an "S", each dot on an "i".

Used heavily, text shadows produce glowing neon signs, retro 3D lettering and embossed labels. Used lightly, they solve a very practical problem: keeping white text readable when it sits on top of a photo. This lesson covers the syntax, layering, those classic effects and how to keep shadowed text accessible.

The syntax

A text shadow has two offsets, an optional blur radius and an optional color:

CSS
h1 {
  /* x-offset  y-offset  blur  color */
  text-shadow: 2px 2px 4px rgb(0 0 0 / 0.4);
}
  • x-offset and y-offset move the shadow right/down (positive) or left/up (negative). Both are required.
  • blur radius (default 0) softens the edge. It can't be negative.
  • color (default currentColor, the text color) can go before or after the lengths.

There is no spread value and no inset keyword, the two big differences from box-shadow.

To remove an inherited shadow, use text-shadow: none. And yes, the property is inherited: set it on a container and every piece of text inside gets it.

Text shadow basics

The last line makes the text itself transparent so only its blurred shadow remains, a dreamy, out-of-focus effect. Note that it's still real, selectable text.

Multiple shadows

Separate shadows with commas. As with box shadows, the first one is drawn on top. Layering is where text shadows get interesting:

CSS
.title {
  text-shadow:
    0 1px 0 #ccc,
    0 2px 0 #bbb,
    0 3px 0 #aaa,
    0 6px 8px rgb(0 0 0 / 0.3);
}

Each hard shadow sits one pixel lower than the last, building a solid "side" for the letters, and the final blurred shadow grounds them on the page.

Classic layered effects
  • Retro 3D: hard shadows, each shifted one more pixel diagonally, plus a soft one at the end.
  • Neon: zero offsets with growing blur radii, from a tight white core to a wide colored glow.
  • Letterpress: a light 1px shadow below and a dark one above make the letters look stamped into the surface.

Effects like these belong on short display text (logos, hero titles, signs), not on paragraphs.

Outlined text

CSS doesn't have a standard "text outline" property, but four hard shadows offset in each direction come close:

CSS
.outlined {
  color: white;
  text-shadow:
    -1px -1px 0 #111,
     1px -1px 0 #111,
    -1px  1px 0 #111,
     1px  1px 0 #111;
}

For thin outlines this looks fine. For thicker ones, gaps appear at the diagonals. The non-standard but universally supported -webkit-text-stroke property draws a real stroke along the glyph edges:

CSS
.stroke {
  -webkit-text-stroke: 2px #111;
  color: transparent; /* hollow letters */
}

The stroke is centered on the edge of each glyph, so thick strokes eat into the letters. Combining a thin stroke with a shadow, or using paint-order: stroke fill in browsers that support it for HTML text, keeps letters full.

Shadows for legibility

The most valuable everyday use of text-shadow is invisible at first glance: a soft, dark shadow behind light text that sits on a photo or a busy background. Where the image is bright, the shadow creates a thin dark halo that separates each letter from the background.

Readable text on a busy image

The left caption almost vanishes on the bright patches; the right one stays readable everywhere, yet the shadow is barely noticeable as a shadow.

A shadow helps, but it isn't a guarantee. Text must still meet contrast requirements against its background, and automated contrast checkers usually ignore shadows. For important text on images, the most reliable approach is a semi-transparent dark overlay or gradient behind the text, with a text shadow as an extra safety net. See Accessible CSS.

A few tips for legibility shadows:

  • Keep the offset small. One or two pixels downward, or none at all. Large offsets read as a decorative effect rather than a halo.
  • Combine a tight and a wide shadow. A small, fairly dark shadow sharpens the edges of each letter; a larger, fainter one darkens the area around the words.
  • Match the shadow to the text. Light text needs a dark shadow; dark text on a dark-and-light image can use a soft white glow instead.
  • Test on the real image. A shadow that works on one photo may be too weak on a brighter one, especially when images are chosen by editors or users.

Keep body text clean

Shadows on paragraphs make edges fuzzy and tire the eyes, especially at small sizes. A good rule: shadows on body text should be close to invisible, or absent. Save visible effects for large display text.

Also remember that shadows don't change layout. A big shadow can spill into the next line or out of a container, and a parent with overflow: hidden will clip it.

Shadows and other features

A few interactions worth knowing:

  • Inheritance: because text-shadow is inherited, a shadow on a hero section also applies to its buttons and links. Reset it with text-shadow: none where you don't want it.
  • Selection: you can change the shadow of selected text with the ::selection pseudo-element. Removing the shadow there often makes selected text easier to read.
  • Gradient text: text filled with a gradient using background-clip: text and a transparent color doesn't combine well with text-shadow, because the shadow is painted above the background and shows through the transparent letters. Use filter: drop-shadow() on the element instead; see Filters and Multiple Backgrounds and background-clip.
  • Animation: shadows can be animated with transitions, for example a glow that grows on hover. Keep the animation short and respect prefers-reduced-motion.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which part of a box-shadow does text-shadow NOT support?

    text-shadow accepts two offsets, a blur and a color. It has no spread radius and no inset keyword.
  2. 2. What does text-shadow: 0 0 12px #22d3ee produce?

    Zero offsets keep the shadow directly behind the text, and the blur spreads it into a glow.
  3. 3. In text-shadow: 1px 1px 0 red, 2px 2px 0 blue, which shadow is on top?

    The first shadow in the list is painted on top.
  4. 4. What is a good use of text-shadow for accessibility?

    A subtle shadow separates letters from busy backgrounds, but you should still ensure real contrast, for example with an overlay.
  5. 5. A hero section has text-shadow set, and now its buttons have shadows too. Why?

    Text shadow is an inherited property. Use text-shadow: none on elements that shouldn't get it.

Summary

  • text-shadow takes x and y offsets, an optional blur and an optional color, and follows the shape of each glyph.
  • It has no spread and no inset, and it is inherited; none removes it.
  • Comma-separated shadows stack with the first on top, enabling 3D, neon and letterpress effects.
  • Four hard shadows or -webkit-text-stroke give outlined text.
  • A subtle dark shadow improves legibility on images, but doesn't replace proper contrast.
  • Keep body text free of visible shadows; save effects for large display text.

Next: Writing Modes and Logical Properties, where text runs vertically and right to left.