CSS text-shadow Property

The CSS text-shadow property adds one or more shadows to text, allowing you to create depth, glowing effects, and decorative typography.

Each shadow is defined using horizontal and vertical offsets, an optional blur radius, and an optional color. Multiple shadows can be combined to produce more complex effects without adding extra HTML elements.

text-shadow Syntax

The text-shadow property accepts one or more shadow definitions or the keyword none.

Basic Syntax

.example {
  text-shadow: 2px 2px 4px #666666;
}

The first two lengths specify the horizontal and vertical offsets. The third length specifies the optional blur radius, and the color determines the shadow's appearance.

General Syntax

.example {
  text-shadow: horizontal-offset vertical-offset blur-radius color;
}

The color may appear before or after the length values. The blur radius and color are optional.

Available Values

.example {
  text-shadow: none;
}
.example {
  text-shadow: 2px 2px;
}
.example {
  text-shadow: 2px 2px 4px;
}
.example {
  text-shadow: 2px 2px 4px red;
}
.example {
  text-shadow: red 2px 2px 4px;
}

Multiple Shadows

.example {
  text-shadow: 1px 1px 2px #333333, 3px 3px 6px #999999;
}

Separate multiple shadow definitions with commas.

CSS-Wide Keywords

.example {
  text-shadow: initial;
}
.example {
  text-shadow: inherit;
}
.example {
  text-shadow: unset;
}
.example {
  text-shadow: revert;
}
.example {
  text-shadow: revert-layer;
}

The initial value is none. Because text-shadow is inherited, unset behaves like inherit.

Valid Examples

.heading {
  text-shadow: 2px 3px #777777;
}
.heading {
  text-shadow: -2px -2px 5px rgb(0 0 0 / 40%);
}
.heading {
  text-shadow: 0 0 10px blue;
}
.heading {
  text-shadow: 1px 1px 2px black, 0 0 8px cyan;
}

Invalid Examples

.example {
  text-shadow: 2px;
}
.example {
  text-shadow: 2px 2px -5px red;
}
.example {
  text-shadow: 2px 2px 4px 6px red;
}
.example {
  text-shadow: inset 2px 2px 4px black;
}
.example {
  text-shadow: 10% 10% 5px black;
}

A shadow requires two offsets. Negative blur radii, spread radii, inset, and percentage offsets are not valid for text-shadow.

Property Values

Value Description
none Removes all text shadows.
Horizontal offset Required length that moves the shadow horizontally. Positive values move it right; negative values move it left.
Vertical offset Required length that moves the shadow vertically. Positive values move it down; negative values move it up.
Blur radius Optional nonnegative length that controls the softness of the shadow. Defaults to zero.
Color Optional color that determines the shadow color. When omitted, the browser determines the default color.
Comma-separated shadows Applies multiple shadows to the same text.

Property Characteristics

Characteristic Value
Initial value none
Inherited Yes
Applies to Text
Computed value none or a list of shadows with absolute lengths and computed colors
Animation type Shadow list
Percentages Not accepted
Negative offsets Allowed
Negative blur radius Not allowed
Specification CSS Text Decoration Module Level 3

Note: Unlike box-shadow, the text-shadow property does not accept a spread radius or an inset keyword.

How It Works

The browser creates a shadow based on the rendered text and positions it using the specified offsets. An optional blur radius softens the shadow's edges.

Step 1: Create a Text Element

<h2 class="shadow-heading">Shadow Example</h2>

Step 2: Add a Shadow

.shadow-heading {
  text-shadow: 3px 3px #888888;
}

The shadow appears three pixels to the right and three pixels below the text.

Step 3: Add Blur

.shadow-heading {
  text-shadow: 3px 3px 5px #888888;
}

The five-pixel blur radius softens the shadow.

Step 4: Use Transparency

.shadow-heading {
  text-shadow: 3px 3px 5px rgb(0 0 0 / 35%);
}

A partially transparent shadow can create a subtler effect.

Step 5: Add Another Shadow

.shadow-heading {
  text-shadow: 1px 1px 2px black, 4px 4px 8px rgb(0 0 0 / 25%);
}

The browser draws both shadows, producing a layered effect.

Important Consideration

Text shadows do not affect the size of the element's layout box. Large shadows can extend outside the element and overlap nearby content.

Horizontal Offset

The first required length controls the horizontal position of the shadow.

Positive Horizontal Offset

.example {
  text-shadow: 4px 0 2px gray;
}

The shadow moves four pixels to the right.

Negative Horizontal Offset

.example {
  text-shadow: -4px 0 2px gray;
}

The shadow moves four pixels to the left.

Zero Horizontal Offset

.example {
  text-shadow: 0 3px 4px gray;
}

The shadow remains horizontally centered beneath the text.

Using em Units

.example {
  text-shadow: 0.1em 0 0.15em gray;
}

Relative units allow the shadow offset to scale with the font size.

Vertical Offset

The second required length controls the vertical position of the shadow.

Positive Vertical Offset

.example {
  text-shadow: 0 4px 2px gray;
}

The shadow moves four pixels downward.

Negative Vertical Offset

.example {
  text-shadow: 0 -4px 2px gray;
}

The shadow moves four pixels upward.

Zero Vertical Offset

.example {
  text-shadow: 3px 0 4px gray;
}

The shadow remains vertically aligned with the text.

Combining Positive and Negative Offsets

.example {
  text-shadow: -3px 4px 5px rgb(0 0 0 / 40%);
}

This places the shadow to the left and below the original text.

Blur Radius

The optional third length controls how soft or diffuse the shadow appears.

No Blur

.example {
  text-shadow: 2px 2px 0 black;
}

The shadow has a sharp edge.

Small Blur Radius

.example {
  text-shadow: 2px 2px 3px black;
}

The shadow has slightly softened edges.

Large Blur Radius

.example {
  text-shadow: 2px 2px 12px black;
}

The shadow spreads visually over a larger area and appears softer.

Zero Offsets With Blur

.example {
  text-shadow: 0 0 10px blue;
}

This creates a glow around the text rather than a shadow displaced in one direction.

Invalid Negative Blur

.example {
  text-shadow: 2px 2px -4px black;
}

The blur radius cannot be negative. Negative values make the declaration invalid.

Important Consideration

Large blur radii can reduce readability and may require more rendering work, especially when applied to many elements.

Shadow Color

The shadow color can be specified using any supported CSS color value.

Named Color

.example {
  text-shadow: 2px 2px 4px navy;
}

Hexadecimal Color

.example {
  text-shadow: 2px 2px 4px #555555;
}

RGB Color

.example {
  text-shadow: 2px 2px 4px rgb(40 80 120);
}

Transparent Color

.example {
  text-shadow: 2px 2px 6px rgb(0 0 0 / 30%);
}

Transparency can make the shadow blend more naturally with the background.

Using currentColor

.example {
  color: #245b85;
  text-shadow: 2px 2px 4px currentColor;
}

The currentColor keyword uses the element's computed text color.

Omitting the Color

.example {
  text-shadow: 2px 2px 4px;
}

When the color is omitted, the browser determines the shadow color. Specify an explicit color when consistent results are important.

Important Consideration

Choose shadow colors that complement the text and background without making the characters difficult to distinguish.

Multiple Text Shadows

The text-shadow property supports multiple comma-separated shadows.

Two Shadows

.example {
  text-shadow: 1px 1px 2px black, 3px 3px 6px gray;
}

Three Shadows

.example {
  text-shadow: 1px 1px 0 #444444, 2px 2px 0 #777777, 3px 3px 0 #aaaaaa;
}

Layering Order

The first shadow in the list is drawn on top of subsequent shadows. This matters when shadows overlap.

Combining Sharp and Blurred Shadows

.example {
  text-shadow: 1px 1px 0 black, 4px 4px 8px rgb(0 0 0 / 35%);
}

The sharp shadow creates a defined edge, while the blurred shadow adds depth.

Combining Colored Glows

.example {
  text-shadow: 0 0 5px cyan, 0 0 15px blue, 0 0 25px navy;
}

Overlapping blurred shadows can create a stronger glow.

Removing Multiple Shadows

.example {
  text-shadow: none;
}

The none keyword removes the entire shadow list.

Important Consideration

Multiple large shadows can make text appear crowded. Use layered effects selectively, especially on small text.

Common Shadow Effects

Different combinations of offsets, blur, and color can create a variety of text effects.

Subtle Drop Shadow

.drop-shadow {
  text-shadow: 1px 2px 3px rgb(0 0 0 / 30%);
}

Sharp Shadow

.sharp-shadow {
  text-shadow: 3px 3px 0 #777777;
}

Soft Glow

.soft-glow {
  text-shadow: 0 0 10px #4a90e2;
}

Neon Glow

.neon-text {
  color: #ffffff;
  text-shadow: 0 0 5px #00ccff, 0 0 15px #00ccff, 0 0 25px #0088ff;
}

Embossed Text

.embossed-text {
  color: #777777;
  text-shadow: 1px 1px 0 #ffffff, -1px -1px 0 #444444;
}

Engraved Text

.engraved-text {
  color: #777777;
  text-shadow: -1px -1px 0 #ffffff, 1px 1px 0 #444444;
}

Layered Depth

.depth-text {
  text-shadow: 1px 1px 0 #555555, 2px 2px 0 #777777, 3px 3px 0 #999999;
}

Text Outline Effect

.outlined-text {
  color: white;
  text-shadow: -1px -1px 0 black, 1px -1px 0 black, -1px 1px 0 black, 1px 1px 0 black;
}

Four sharp shadows can approximate a thin outline. This is a decorative technique rather than a replacement for a dedicated text-stroke feature.

Important Consideration

Decorative effects should remain readable at different font sizes and against different backgrounds.

text-shadow vs. box-shadow

The text-shadow and box-shadow properties create shadows around different parts of an element.

Text Shadow

.text-example {
  text-shadow: 2px 2px 4px gray;
}

The shadow follows the rendered text shapes.

Box Shadow

.box-example {
  box-shadow: 2px 2px 4px gray;
}

The shadow follows the element's box.

Comparison

Feature text-shadow box-shadow
Shadow target Text Element box
Horizontal offset Yes Yes
Vertical offset Yes Yes
Blur radius Yes Yes
Spread radius No Yes
Inset shadows No Yes
Multiple shadows Yes Yes
Inherited Yes No

Using Both Properties

.shadow-card {
  padding: 20px;
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}
.shadow-card h2 {
  text-shadow: 1px 2px 3px rgb(0 0 0 / 25%);
}

The card receives a box shadow, while its heading receives a text shadow.

Inheritance

The text-shadow property is inherited. Descendant text normally uses the shadow defined on its parent unless it is overridden.

Inherited Shadow

.article {
  text-shadow: 1px 1px 2px gray;
}

Text within the article inherits the shadow.

Overriding the Parent Shadow

.article {
  text-shadow: 1px 1px 2px gray;
}
.article .special-heading {
  text-shadow: 2px 2px 5px blue;
}

Removing an Inherited Shadow

.article .plain-text {
  text-shadow: none;
}

Explicit Inheritance

.child {
  text-shadow: inherit;
}

Restoring the Initial Value

.child {
  text-shadow: initial;
}

This restores none.

Using unset

.child {
  text-shadow: unset;
}

Because the property is inherited, unset uses the parent's computed shadow value.

Important Consideration

A shadow applied to a parent can affect headings, paragraphs, links, and other descendant text. Use targeted selectors when only specific elements need shadows.

Animation

The text-shadow property can be animated to create changing shadow positions, colors, and blur effects.

Transition Example

.animated-heading {
  text-shadow: 1px 1px 2px gray;
  transition: text-shadow 0.3s ease;
}
.animated-heading:hover {
  text-shadow: 3px 3px 8px blue;
}

Glowing Animation

.glowing-heading {
  animation: text-glow 2s ease-in-out infinite alternate;
}
@keyframes text-glow {
  from {
    text-shadow: 0 0 2px #4a90e2;
  }
  to {
    text-shadow: 0 0 12px #4a90e2;
  }
}

Animated Shadow Movement

.moving-shadow {
  animation: shadow-move 2s ease-in-out infinite alternate;
}
@keyframes shadow-move {
  from {
    text-shadow: -3px 2px 3px gray;
  }
  to {
    text-shadow: 3px 2px 3px gray;
  }
}

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .glowing-heading,
  .moving-shadow {
    animation: none;
  }
}

This disables the animations for users who request reduced motion.

Important Consideration

Continuous shadow animations may be distracting and can require additional painting work. Use them sparingly.

Practical Examples

Subtle Heading Shadow

.page-heading {
  text-shadow: 1px 2px 3px rgb(0 0 0 / 20%);
}

Hero Banner Text

.hero-title {
  color: white;
  text-shadow: 0 2px 6px rgb(0 0 0 / 65%);
}

Blue Glow

.blue-glow {
  text-shadow: 0 0 8px #0088ff;
}

Sharp Offset Shadow

.offset-heading {
  text-shadow: 4px 4px 0 #cccccc;
}

Layered Shadow

.layered-heading {
  text-shadow: 1px 1px 0 #555555, 2px 2px 0 #888888, 3px 3px 0 #bbbbbb;
}

Light Text on a Dark Background

.dark-panel-heading {
  color: white;
  text-shadow: 0 0 6px rgb(255 255 255 / 35%);
}

Text Outline

.outlined-heading {
  color: white;
  text-shadow: -1px -1px 0 black, 1px -1px 0 black, -1px 1px 0 black, 1px 1px 0 black;
}

Hover Shadow

.hover-heading {
  text-shadow: none;
  transition: text-shadow 0.2s ease;
}
.hover-heading:hover {
  text-shadow: 2px 2px 5px rgb(0 0 0 / 40%);
}

Responsive Shadow

.responsive-heading {
  text-shadow: 3px 3px 6px rgb(0 0 0 / 35%);
}
@media (max-width: 600px) {
  .responsive-heading {
    text-shadow: 1px 1px 3px rgb(0 0 0 / 25%);
  }
}

Remove a Shadow

.plain-heading {
  text-shadow: none;
}

text-shadow Example

This example compares several text-shadow effects using different offsets, blur radii, and colors. Each sample demonstrates how a shadow changes the appearance of the same text.

HTML Example

<div class="text-shadow-demo">
  <div class="shadow-sample">
    <strong>No Shadow</strong>
    <p class="shadow-none">Shadow Example</p>
  </div>
  <div class="shadow-sample">
    <strong>Drop Shadow</strong>
    <p class="shadow-drop">Shadow Example</p>
  </div>
  <div class="shadow-sample">
    <strong>Sharp Shadow</strong>
    <p class="shadow-sharp">Shadow Example</p>
  </div>
  <div class="shadow-sample">
    <strong>Blue Glow</strong>
    <p class="shadow-glow">Shadow Example</p>
  </div>
  <div class="shadow-sample">
    <strong>Multiple Shadows</strong>
    <p class="shadow-multiple">Shadow Example</p>
  </div>
</div>

CSS Example

.text-shadow-demo {
  display: grid;
  gap: 16px;
}
.text-shadow-demo .shadow-sample {
  padding: 18px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}
.text-shadow-demo strong {
  display: block;
  margin-bottom: 10px;
  color: #334155;
  font-size: 14px;
}
.text-shadow-demo p {
  margin: 0;
  color: #1f2937;
  font-family: Georgia, serif;
  font-size: 28px;
  line-height: 1.5;
}
.text-shadow-demo .shadow-none {
  text-shadow: none;
}
.text-shadow-demo .shadow-drop {
  text-shadow: 2px 3px 4px rgb(0 0 0 / 35%);
}
.text-shadow-demo .shadow-sharp {
  text-shadow: 3px 3px 0 #aaaaaa;
}
.text-shadow-demo .shadow-glow {
  text-shadow: 0 0 8px #0088ff;
}
.text-shadow-demo .shadow-multiple {
  text-shadow: 1px 1px 0 #777777, 3px 3px 6px rgb(0 0 0 / 35%);
}
Browser Result
No Shadow

Shadow Example

Drop Shadow

Shadow Example

Sharp Shadow

Shadow Example

Blue Glow

Shadow Example

Multiple Shadows

Shadow Example

Comparing the Results

Sample Expected Appearance
No Shadow Text appears without any shadow effect.
Drop Shadow A soft shadow appears below and to the right of the text.
Sharp Shadow A defined shadow appears with no blur.
Blue Glow A blue glow surrounds the text.
Multiple Shadows Two overlapping shadows create additional depth.

Changing the Shadow Direction

.text-shadow-demo .shadow-drop {
  text-shadow: -3px -3px 4px rgb(0 0 0 / 35%);
}

The shadow moves above and to the left of the text.

Increasing the Blur

.text-shadow-demo .shadow-glow {
  text-shadow: 0 0 16px #0088ff;
}

The glow becomes more diffuse.

Removing the Blur

.text-shadow-demo .shadow-drop {
  text-shadow: 2px 3px 0 #777777;
}

The shadow becomes sharp and clearly defined.

Accessibility Considerations

Text shadows can improve visual separation in some designs, but excessive effects can reduce readability.

Maintain Text Contrast

Ensure that the text itself has sufficient contrast against its background. Do not rely on shadows alone to satisfy contrast requirements.

Avoid Excessive Blur

Large, dark, or overlapping shadows can make individual characters difficult to distinguish.

Use Shadows Sparingly on Body Text

Decorative shadows are generally better suited to headings and short labels than long paragraphs.

Test Different Font Sizes

Shadows that look appropriate on large headings may appear crowded on small text.

Consider Background Images

A subtle shadow can help separate text from a background image, but a suitable overlay or solid background may provide more reliable readability.

Avoid Rapid Shadow Animations

Flashing or rapidly changing glow effects can be distracting and may create accessibility concerns.

Respect Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .animated-shadow {
    animation: none;
    transition: none;
  }
}

Test Across Devices

Shadow appearance can vary with screen resolution, font rendering, and display settings.

Preserve Readable Text

Do not use shadows to replace actual text or create essential information that is only visible through a decorative effect.

Common Mistakes

Providing Only One Offset

.example {
  text-shadow: 3px;
}

Both horizontal and vertical offsets are required.

Using a Negative Blur Radius

.example {
  text-shadow: 2px 2px -4px black;
}

Blur radii cannot be negative.

Using a Spread Radius

.example {
  text-shadow: 2px 2px 4px 6px black;
}

The text-shadow property does not support a spread radius.

Using inset

.example {
  text-shadow: inset 2px 2px 4px black;
}

Inset shadows are not supported by text-shadow.

Using Percentage Offsets

.example {
  text-shadow: 10% 10% 5px black;
}

Offsets must use valid CSS lengths, not percentages.

Forgetting Commas Between Shadows

.example {
  text-shadow: 1px 1px 2px black 3px 3px 6px gray;
}

Separate each shadow definition with a comma.

Applying Shadows to Too Much Text

Because the property is inherited, applying it to a large container can affect many descendant text elements.

Using Excessively Large Shadows

Large offsets and blur radii can overlap nearby content.

Ignoring Background Contrast

A shadow that looks good on a light background may be difficult to see on a dark background.

Confusing text-shadow With box-shadow

Use text-shadow for text and box-shadow for element boxes.

Expecting Shadows to Affect Layout

Text shadows do not increase the space reserved for an element.

Using Shadows as the Only Visual Indicator

Important information should remain understandable without decorative shadow effects.

Important Considerations

Keep the following points in mind when using text-shadow:

  • The property adds one or more shadows to rendered text.
  • The initial value is none.
  • The property is inherited.
  • Each shadow requires horizontal and vertical offsets.
  • The blur radius is optional.
  • The shadow color is optional, but specifying one provides more predictable results.
  • Positive horizontal offsets move shadows to the right.
  • Negative horizontal offsets move shadows to the left.
  • Positive vertical offsets move shadows downward.
  • Negative vertical offsets move shadows upward.
  • Negative blur radii are invalid.
  • Percentage offsets are not accepted.
  • Spread radii are not supported.
  • The inset keyword is not supported.
  • Multiple shadows are separated by commas.
  • The first shadow in a list is drawn above subsequent shadows.
  • Zero offsets with a blur radius can create a glow.
  • Sharp shadows can approximate outlines and layered depth effects.
  • Transparent colors can produce softer-looking shadows.
  • The currentColor keyword can use the element's text color.
  • Shadows do not affect the element's layout dimensions.
  • Large shadows may extend beyond the element's box.
  • The property can be animated.
  • Continuous shadow animations may require additional rendering work.
  • Shadows should not replace sufficient text contrast.
  • Decorative effects should be tested at different font sizes and screen widths.
  • Use box-shadow when the shadow should follow an element's box rather than its text.

Browser Support

The CSS text-shadow property is widely available in modern browsers, including current versions of Chrome, Edge, Firefox, and Safari.

Standard single and multiple text shadows are broadly supported without vendor prefixes.

For current compatibility information, visit Can I Use? and search for text-shadow.

Widely Supported Example

.heading {
  text-shadow: 2px 2px 4px rgb(0 0 0 / 35%);
}

Multiple Shadow Example

.heading {
  text-shadow: 1px 1px 2px black, 3px 3px 6px gray;
}

Feature Detection

@supports (text-shadow: 2px 2px 4px black) {
  .heading {
    text-shadow: 2px 2px 4px black;
  }
}

Feature detection is generally unnecessary for standard text shadows because browser support is widespread.

Testing Recommendations

Test large shadows, multiple layers, and animated effects across browsers and devices to confirm that they remain readable and do not overlap important content.

Specifications

The text-shadow property is defined in the CSS Text Decoration Module Level 3 specification.

CSS Text Decoration Module Level 3 - text-shadow Property

The specification defines shadow offsets, blur radii, colors, multiple shadows, and painting behavior.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: text-shadow