← Back to CSS Course | Chapter 4: Text & Fonts | Lesson 3 of 10

CSS Text Effects

Beyond text-shadow, which already has full coverage in CSS Shadows, CSS offers several other ways to give text a stylized, decorative treatment — outlined strokes, gradient fills, and spacing-based typographic flourishes.
Syntax
css
selector {
  text-shadow: h-offset v-offset blur color;
  text-overflow: ellipsis;
  word-wrap: break-word;
}

Outlined Text with -webkit-text-stroke

The non-standard but widely-supported -webkit-text-stroke property draws an outline around each letter's glyph shape, distinct from text-shadow which blurs a colored copy behind the text. It takes a width and color, and is often combined with a transparent fill for a pure outline effect.

Note:
  • Accepted values:
  • webkit-text-stroke-width — length, e.g. 1px
  • webkit-text-stroke-color — any color value
  • shorthand — e.g. 1px black
  • webkit-text-fill-color — transparent gives a hollow outline

Example: Outlined Text with -webkit-text-stroke

css
<style>
h1 {
  -webkit-text-stroke: 2px black;
  color: transparent;
}
</style>
<h1>Outlined Text</h1>

Gradient Text with background-clip

Gradient-filled text is achieved by applying a background gradient to the text element, then using background-clip: text with a transparent text color so the gradient shows through the letter shapes instead of filling a rectangular box. This is a widely used trick for eye-catching headings.

Example: Gradient Text with background-clip

css
<style>
h1 {
  background: linear-gradient(90deg, purple, orange);
  background-clip: text;
  color: transparent;
}
</style>
<h1>Gradient Heading</h1>

Letter and Word Spacing for Typographic Style

letter-spacing and word-spacing adjust the gap between individual characters and between words respectively. Wide letter-spacing on uppercase text is a very common stylistic choice for headings and labels, giving a more spacious, deliberate, "designed" feel compared to default tight spacing.

Note:
  • Accepted values:
  • letter-spacing: normal | <length> — e.g. 2px or 0.1em (may be negative)
  • word-spacing: normal | <length> | <percentage> — extra space between words
  • inherit | initial | unset | revert — CSS-wide keywords accepted by every property

Example: Letter and Word Spacing for Typographic Style

css
<style>
h2 {
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
</style>
<h2>Designed Heading</h2>

Text Decoration Beyond Simple Underlines

text-decoration-style (solid, double, dotted, dashed, wavy) and text-decoration-thickness give creative control over underlines beyond the default thin solid line, while text-underline-offset moves the underline further from the text so it doesn't crowd descenders like "g" or "y".

Example: Text Decoration Beyond Simple Underlines

css
<style>
a {
  text-decoration-style: wavy;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
</style>
<a href="#">Wavy underline, offset from the text</a>

Combining Effects for a Signature Heading Style

The most striking text treatments usually combine several of these techniques at once — a gradient fill, a subtle stroke, and deliberate letter-spacing together — rather than relying on any single property alone.

As with most CSS effects, restraint matters: combining every technique on every heading quickly looks noisy rather than polished.

Example: Combining Effects for a Signature Heading Style

css
<style>
h1 {
  background: linear-gradient(90deg, purple, orange);
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px black;
  letter-spacing: 0.05em;
}
</style>
<h1>Signature Heading</h1>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Expecting -webkit-text-stroke to draw only outside the letters, when the stroke is centered on the outline and thins the letter fill.
  2. Using background-clip: text without color: transparent so the gradient is hidden.
  3. Adding too much letter spacing, which makes words hard to read.
Browser Support

Supported in all modern browsers: Chrome, Firefox, Safari, Edge and Opera. Text stroke and gradient text (background-clip: text) still rely on the -webkit- prefix in some browsers.

🔒

Chapter Quiz — Complete all 10 topics to unlock

0/10 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.