Menu

Text Shadow CSS: Syntax, Glow, Outline and Examples

text-shadow draws one or more shadows behind text. Learn the four values (x offset, y offset, blur, color), how to stack shadows for glow, outline and 3D effects, and how to use a shadow to keep text readable on busy backgrounds.

This page includes runnable editors - edit, run, and see output instantly.

How text-shadow works

text-shadow paints a copy of the text behind it, moved and blurred. You give it a horizontal offset, a vertical offset, an optional blur and a color.

3px 3px 0 #f59e0b means 3px right (physical, in every writing direction), 3px down, no blur, amber. The second shadow blurs 6px and uses a semi-transparent black, which is the usual recipe for a subtle depth effect.

The syntax

text-shadow: <offset-x> <offset-y> <blur-radius>? <color>?;
ValueRequiredMeaning
offset-xYesPositive moves the shadow right, negative moves it left
offset-yYesPositive moves it down, negative moves it up
blur-radiusNo (default 0)How soft the edge is; negative values are invalid
colorNo (default the text color)Can come first or last

text-shadow: none removes an inherited shadow. Change the values below to see each one's effect:

Try -4px -4px 0 #16a34a, 0 0 10px red, and two shadows separated by a comma.

Multiple shadows: glow, outline and 3D

Commas stack shadows; the first one is drawn on top. Three effects come from that one rule:

  • Glow: zero offsets, growing blur, on a dark background.
  • Outline: four hard shadows, one per diagonal. It works for thin outlines; for a thicker even outline, -webkit-text-stroke: 2px #111827 (supported in all current browsers despite the prefix) draws a stroke on the letter edges instead.
  • 3D: a series of hard shadows each 1px further, so the letters look extruded.

Keeping text readable on a busy background

White text on a photo or a pattern loses its edges where the background is light. A soft dark shadow brings them back without a visible box:

A shadow helps, but it is not a guarantee of contrast. For long text over an image, add a solid or gradient overlay behind the text as well.

text-shadow vs box-shadow

text-shadowbox-shadow
FollowsThe letter shapesThe element's box (and its border radius)
Spread valueNoYes
insetNoYes
Multiple, comma-separatedYesYes

For shadows on cards and buttons, see box-shadow.

Common mistakes

  • Heavy, dark shadows on body text. They blur the letter shapes. Keep shadows for headings and short labels.
  • Forgetting the second offset. text-shadow: 2px #000 is invalid; both offsets are required.
  • A negative blur. It is invalid and the whole declaration is dropped.
  • Expecting the shadow to take space. It is painted only; big shadows can overlap the next line or be cut off by overflow: hidden.
  • Glow effects on light backgrounds. A light glow on white is invisible. Glows need a dark background.

Frequently Asked Questions

What is the syntax of text-shadow?

text-shadow: offset-x offset-y blur-radius color;, for example text-shadow: 2px 2px 4px rgb(0 0 0 / 40%);. The two offsets are required; blur defaults to 0 and color to the text color.

How do I add more than one text shadow?

Separate the shadows with commas: text-shadow: 0 0 4px #fff, 0 0 12px #2563eb;. The first shadow is drawn on top of the ones after it.

How do I make a glow effect on text?

Use shadows with no offset and a blur, often several with growing blur: text-shadow: 0 0 4px #60a5fa, 0 0 12px #2563eb;. On a dark background it reads as a neon glow.

Does text-shadow have a spread value like box-shadow?

No. text-shadow has no spread and no inset keyword. To thicken the shadow around letters, stack several shadows or use -webkit-text-stroke for an outline.

Does text-shadow affect layout?

No. The shadow is painted only; it takes no space and does not move surrounding content, so a large shadow can overlap nearby elements.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED