Course contentsShow
← Web Development
Lesson 205 of 2,9823. CSS FundamentalsFree lesson

Text Shadow

Apply shadows to text with text-shadow, understanding differences from box-shadow.

Text Shadow

What you'll learn: How to add shadow effects to text using text-shadow, and how it differs from box-shadow.

The Core Concept

While box-shadow creates shadows around entire elements, text-shadow applies shadows specifically to the letters of your text content. Think of it like a shadow cast by each individual character rather than the box containing them.

The text-shadow property uses a similar syntax to box-shadow, but with a key difference: it has no spread value and no inset option. The text itself is always the "solid object" casting the shadow.

Basic Syntax

text-shadow: horizontal-offset vertical-offset blur-radius color;
  • Horizontal offset (required): Moves shadow left (negative) or right (positive)
  • Vertical offset (required): Moves shadow up (negative) or down (positive)
  • Blur radius (optional): How soft the shadow edges are (defaults to 0)
  • Color (optional): Shadow color (defaults to text color)

Example

h1 {
  color: #2c3e50;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

This creates a subtle shadow 2px right, 2px down, with a 4px blur.

Multiple Text Shadows

Like box-shadow, you can layer multiple text shadows:

h2 {
  text-shadow: 
    1px 1px 2px rgba(0, 0, 0, 0.5),
    -1px -1px 2px rgba(255, 255, 255, 0.3);
}

Key Differences from Box-Shadow: text-shadow has no spread radius and no inset keyword—it only follows the outline of your text characters, not the element box. It's perfect for creating depth, glow effects, or improving text readability over backgrounds.