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

Text Shadow

Add depth and emphasis to text using text-shadow with offset, blur, and color values.

Text Shadow

What you'll learn: How to add depth and visual interest to text using CSS shadows with customizable offset, blur, and color.


Why Add Shadows to Text?

Text shadow is a CSS property that creates a shadow effect behind your text, making it stand out from the background. Think of it like the shadow your hand casts on a wall when you hold it near a lamp — you can control where the shadow falls, how soft or sharp it is, and what color it appears.

This effect can improve readability (like white text on a light background), create depth, or add stylistic flair to headings and important text.

The text-shadow Syntax

The text-shadow property takes up to four values:

text-shadow: horizontal-offset vertical-offset blur-radius color;
  • Horizontal offset: How far right (positive) or left (negative) the shadow moves
  • Vertical offset: How far down (positive) or up (negative) the shadow moves
  • Blur radius (optional): How soft the shadow edges are (0 = sharp, higher = softer)
  • Color (optional): The shadow's color (defaults to text color if omitted)

Examples in Action

h1 {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  /* Shadow: 2px right, 2px down, 4px blur, semi-transparent black */
}

.glow {
  text-shadow: 0 0 10px #00ff00;
  /* No offset, just a 10px green glow around the text */
}

.hard-shadow {
  text-shadow: 3px 3px 0 #333;
  /* Sharp shadow (no blur) offset 3px right and down */
}

You can even layer multiple shadows by separating them with commas!

Key Takeaway: The text-shadow property adds visual depth to text using horizontal/vertical offsets, optional blur radius, and color — essential for emphasis and readability enhancement.