CSS Text Effects
Create stunning text effects with shadows, gradients, animations, and modern CSS techniques. Make your typography stand out with visual impact.
How do you add effects to text with CSS?
Common text effects use text-shadow for glows and shadows, background-clip: text for gradient or image-filled text, -webkit-text-stroke for outlined text, and text-overflow: ellipsis for truncation. Keep body text plain: effects are for headings and short display text, and contrast must stay readable.
.glow { text-shadow: 0 0 8px rgb(59 130 246 / .8); }
.outline { -webkit-text-stroke: 1px #111; color: transparent; }
.gradient {
background: linear-gradient(90deg, #06b6d4, #8b5cf6);
background-clip: text; -webkit-background-clip: text;
color: transparent;
}Interactive Text Effects Demo
Code Editor
<h1 class="glow">Glow</h1>
<h1 class="outline">Outline</h1>
<h1 class="gradient">Gradient</h1>
<p class="clamp">This long paragraph is clamped to two lines with an ellipsis, no matter how much text it contains. Add more words in the HTML tab and it still stops after the second line.</p>Preview
Text Shadow Mastery
Text shadows are the foundation of text effects. They add depth, improve readability, and can create dramatic visual impact when used creatively.
Basic Shadow
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);Simple offset shadow for depth
Glow Effect
text-shadow: 0 0 10px #3b82f6;No offset creates a glow
Multiple Shadows
text-shadow: 1px 1px 0 #ccc, 2px 2px 0 #bbb;Layer shadows for 3D effect
Gradient Text
Gradient text creates vibrant, modern effects that work great for headings and call-to-action text. Uses background-clip for the effect.
Gradient Text Technique
background: linear-gradient(45deg, #667eea, #764ba2);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;Always include -webkit- prefixes for gradient text. Consider fallback colors for older browsers.
Animation Effects
Typewriter Effect
- • Uses width animation with overflow hidden
- • Blinking cursor with border-right
- • Steps timing function for realistic typing
- • Great for hero sections and intros
Text Reveal
- • Sliding overlay technique
- • Pseudo-element animations
- • Works well with scroll triggers
- • Creates anticipation and focus
Performance & Best Practices
Best Practices
- • Use text effects sparingly for maximum impact
- • Consider accessibility and readability
- • Test with different font sizes
- • Provide fallbacks for older browsers
- • Respect prefers-reduced-motion
Performance Tips
- • Use transform instead of position changes
- • Limit complex shadows on large text blocks
- • Optimize animations with will-change
- • Consider GPU acceleration
- • Test on mobile devices
CSS Text Effects — step by step
text-shadow
Add shadows to text with text-shadow: x y blur color. Stack multiple shadows with commas for neon glow or 3D emboss effects.
🎯 Quick Check
Which combination creates gradient-colored text?
CSS Text Effects: summary
Key points
text-shadowtakes x-offset, y-offset, blur and colour, and accepts several comma-separated shadows.-webkit-line-clamp: 3withdisplay: -webkit-box; -webkit-box-orient: vertical; overflow: hidden;truncates text to three lines.writing-mode: vertical-rlturns text vertical for side labels.
Frequently asked questions
›How do I limit text to 2 lines with an ellipsis?
Use display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;. It works in all modern browsers despite the prefix.