🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

Text-shadow

AI & DATA SCIENCE // text-shadow

The text-shadow property adds one or more shadow effects behind an element's text, specified as a horizontal offset, vertical offset, optional blur radius, and color.

Syntax

text-shadow: h-offset v-offset blur color;

Deep Dive Course

The first two length values set the shadow's horizontal and vertical offset from the original text, positive values shifting it right and down respectively, an optional third length value sets the blur radius, softening the shadow's edges the larger it is, and the final value sets the shadow's color. Multiple shadows can be layered by separating complete shadow definitions with commas, each rendering independently behind the text, which is a common technique for creating a more elaborate glow or multi-layered depth effect beyond what a single shadow alone can achieve.

1Understanding Text-shadow

The first two length values set the shadow's horizontal and vertical offset from the original text, positive values shifting it right and down respectively, an optional third length value sets the blur radius, softening the shadow's edges the larger it is, and the final value sets the shadow's color. Multiple shadows can be layered by separating complete shadow definitions with commas, each rendering independently behind the text, which is a common technique for creating a more elaborate glow or multi-layered depth effect beyond what a single shadow alone can achieve.

💡

Setting the horizontal and vertical offsets both to 0, paired with a nonzero blur radius, creates an even glow effect surrounding the text in every direction, rather than a directional drop-shadow offset to one side.

editor.html
.hero-title {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
localhost:3000

2Practical Example

Here is a real-world application of Text-shadow showing how it is used in production CSS code.

editor.html
.glow-text {
  color: white;
  text-shadow: 0 0 10px #00f0ff;
}
localhost:3000

3Best Practices

Follow these guidelines when working with Text-shadow:

1. Use a subtle offset and blur, rather than large, harsh values, for a tasteful drop-shadow effect that improves text legibility over a busy or image background without looking heavy-handed

2. Set both offsets to 0 with a blur radius for an even glow effect surrounding the text uniformly, rather than a directional shadow

3. Layer multiple comma-separated text-shadow values for more elaborate effects, like combining a tight, dark shadow for depth with a larger, colored one for glow

⚠️

Tip: Setting the horizontal and vertical offsets both to 0, paired with a nonzero blur radius, creates an even glow effect surrounding the text in every direction, rather than a directional drop-shadow offset to one side.

editor.html
.hero-title {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
localhost:3000

Examples

Example 01Basic Usage
.hero-title {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
Example 02Advanced Example
.glow-text {
  color: white;
  text-shadow: 0 0 10px #00f0ff;
}

Best Practices

  • Use a subtle offset and blur, rather than large, harsh values, for a tasteful drop-shadow effect that improves text legibility over a busy or image background without looking heavy-handed
  • Set both offsets to 0 with a blur radius for an even glow effect surrounding the text uniformly, rather than a directional shadow
  • Layer multiple comma-separated text-shadow values for more elaborate effects, like combining a tight, dark shadow for depth with a larger, colored one for glow

Interview Question

Why does setting text-shadow's horizontal and vertical offsets to 0, while keeping a nonzero blur value, produce an even glow effect rather than a directional drop shadow?

Hint: Think about what the offset values actually control, versus what the blur radius controls, and what's left once the offset contributes nothing at all.

The horizontal and vertical offset values specifically determine how far, and in which direction, the shadow copy of the text is shifted away from the original text's exact position, which is precisely what creates the visual impression of a shadow being cast off to one particular side, as if from a directional light source. Setting both of these offsets to 0 means the shadow copy is positioned in the exact same place as the original text, with no directional displacement in any direction at all, so any visual effect that remains comes entirely from the blur radius, which spreads and softens the shadow's edges outward symmetrically in every direction from that shared, undisplaced position, rather than in any single, offset-determined direction. This symmetric, non-directional spreading around the text's own exact position is precisely what visually reads as an even glow surrounding the text, rather than a shadow that appears to be cast off to one particular side the way a nonzero offset would produce.

Exercises

MediumPractice using Text-shadow in a real scenario.
View Solution
.hero-title {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

Frequently Asked Questions

Why does setting text-shadow's horizontal and vertical offsets to 0, while keeping a nonzero blur value, produce an even glow effect rather than a directional drop shadow?

The horizontal and vertical offset values specifically determine how far, and in which direction, the shadow copy of the text is shifted away from the original text's exact position, which is precisely what creates the visual impression of a shadow being cast off to one particular side, as if from a directional light source. Setting both of these offsets to 0 means the shadow copy is positioned in the exact same place as the original text, with no directional displacement in any direction at all, so any visual effect that remains comes entirely from the blur radius, which spreads and softens the shadow's edges outward symmetrically in every direction from that shared, undisplaced position, rather than in any single, offset-determined direction. This symmetric, non-directional spreading around the text's own exact position is precisely what visually reads as an even glow surrounding the text, rather than a shadow that appears to be cast off to one particular side the way a nonzero offset would produce.

Related Functions

Font-familyColorFilter