CSS Reference ยท Typography
The text-shadow property
Reference for the CSS text-shadow property: offsets, blur radius and color, multiple shadows, glow and outline effects, readability tips, syntax and browser support.
The text-shadow property draws one or more shadows behind the characters of an element. Each shadow is a copy of the text, moved by a horizontal and a vertical offset, optionally blurred, and painted in a color you choose. Shadows follow the glyph shapes, not the element's box, which separates it from box-shadow.
A shadow needs at least two lengths (the offsets). A third length is the blur radius. The color can come first or last; if you leave it out, the shadow uses the element's current text color.
h1 { text-shadow: 2px 3px 4px rgb(0 0 0 / 0.35); }
Try it
Syntax
text-shadow: none | <shadow># /* <shadow> */ <color>? && <length>{2,3} /* offset-x offset-y blur-radius (optional) */
- Initial value:
none - Applies to: all elements, plus
::first-lineand::first-letter - Inherited: yes
- Animatable: yes (shadow lists are interpolated)
- Computed value:
none, or a list of shadows with the color computed and the lengths made absolute
Values
| Value | Description |
|---|---|
none |
No shadow. Use it to remove a shadow set elsewhere. |
| offset-x | Horizontal distance. Positive moves the shadow right, negative left. Required. |
| offset-y | Vertical distance. Positive moves the shadow down, negative up. Required. |
| blur radius | Optional length, never negative. 0 (the default) gives a sharp copy; larger values spread and soften it. |
| color | Any CSS color. Defaults to currentcolor. Semi-transparent colors look more natural than solid gray. |
| comma-separated list | Several shadows at once. The first shadow in the list is painted on top. |
There is no spread value. If you need a thicker shadow, stack several shadows or use a filter such as drop-shadow().
Usage notes
- Layering order. In a list, the first shadow is on top, so put tight, dark shadows first and large glows last.
- Legibility first. A subtle shadow can lift white text off a photo, but heavy shadows on small text hurt readability. Check contrast against the background, not against the shadow.
- Shadows paint with the text. They also follow text decorations such as underlines, and they appear even when the text color is transparent, which enables effects like text that is only a shadow.
- Not clipped by the box. A large blur can extend past the element, and it may be cut off by an ancestor with
overflowother thanvisible. - Cost. Large blurs on lots of text, especially when animated, can be expensive to paint. Prefer short lists and animate sparingly.
- Emoji and color fonts are drawn with their own colors, but the shadow still takes the shape of the glyph.
Browser support
Supported in every current browser, and has been for many years.
Related
box-shadowโ shadow around the element's boxcolorโ the text color the shadow defaults totext-decorationโ underlines and strike-throughs- Lesson: Text Shadow
- Lesson: Text Styling