Support0

CSS text-shadow playground

Combine up to three text shadows, adjust their offsets, blur, and color, and generate copy-ready code.

Ask AI

CSS text-shadow playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.

Shadows that add depth to text

HTML
<h2 class="text-shadow-sample">Shadows that add depth to text</h2>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<h2 class="box-border grid min-block-72 min-w-0 w-full max-w-2xl place-items-center p-6 bg-[#4f46e5] text-[#f8fafc] text-[64px] font-black leading-[1.05] text-center text-balance wrap-anywhere text-shadow-[3px_5px_8px_#17203399]">Shadows that add depth to text</h2>
CSS
.text-shadow-sample {
  box-sizing: border-box;
  inline-size: min(100%, 42rem);
  min-inline-size: 0;
  min-block-size: 18rem;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background-color: #4f46e5;
  color: #f8fafc;
  font-size: 64px;
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  text-wrap: balance;
  overflow-wrap: anywhere;
  text-shadow: 3px 5px 8px #17203399;
}

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.

  1. 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.

  2. 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.

  3. Shadow color

    Pick an explicit color to control the effect. A color with alpha lets some of the paint behind it show through.

Static diagram of a text shadowEach layer has two offsets and can include a blur radius and a color. The initial value is none, and the property inherits.

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

In the first sample, the blue shadow appears next to the letters. In the second, it follows the outer edge of the box, even where there is no text.
The same letters and the same offset
<div class="text-shadow-guide-geometry">
  <div>
    <p>text-shadow</p>
    <p class="sample glyphs">Aa</p>
  </div>
  <div>
    <p>box-shadow</p>
    <p class="sample box">Aa</p>
  </div>
</div>
.text-shadow-guide-geometry {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
  gap: 1rem;
  padding: 0 0.5rem 0.5rem;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 0.5rem;
  }

  .sample {
    margin: 0;
    padding: 0.5rem;
    background-color: #f8fafc;
    color: #172033;
    font-size: 2rem;
    font-weight: 800;
  }

  .glyphs {
    text-shadow: 4px 4px 0 #2563eb;
  }

  .box {
    box-shadow: 4px 4px 0 #2563eb;
  }
}

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

Both samples use the same offsets, colors, and order. The blur radii change. The nearer layer goes from 0 to 2 px and the farther one from 0 to 8 px.
The same two layers with sharp or soft edges
<div class="text-shadow-guide-layers">
  <div>
    <p>Sharp edges</p>
    <p class="sample sharp">Depth</p>
  </div>
  <div>
    <p>Soft edges</p>
    <p class="sample soft">Depth</p>
  </div>
</div>
.text-shadow-guide-layers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
  gap: 1rem;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 0.5rem;
  }

  .sample {
    margin: 0;
    padding: 0.75rem;
    background-color: #0f172a;
    color: #fef3c7;
    font-size: 2rem;
    font-weight: 800;
  }
}

.text-shadow-guide-layers .sharp {
  text-shadow:
    3px 3px 0px #0369a1,
    6px 6px 0px #9f1239;
}

.text-shadow-guide-layers .soft {
  text-shadow:
    3px 3px 2px #0369a1,
    6px 6px 8px #9f1239;
}

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

Both samples have the same light text and dark blue background. The second adds a soft shadow. Both remain readable when the browser removes the shadow.
The same notice on an opaque background
<div class="text-shadow-guide-contrast">
  <div>
    <p>Without a shadow</p>
    <p class="sample plain">Registration is open</p>
  </div>
  <div>
    <p>With a shadow</p>
    <p class="sample shaded">Registration is open</p>
  </div>
</div>
.text-shadow-guide-contrast {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
  gap: 1rem;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 0.5rem;
  }

  .sample {
    margin: 0;
    padding: 0.5rem;
    background-color: #1e3a8a;
    color: #f8fafc;
  }

  .plain {
    text-shadow: none;
  }

  .shaded {
    text-shadow: 0 2px 4px #020617;
  }
}

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.