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

CSS Text Effects

text-shadow से आगे, जिसकी पूरी coverage CSS Shadows में पहले से है, CSS text को stylized, decorative treatment देने के कई और तरीके offer करता है — outlined strokes, gradient fills, और spacing-based typographic flourishes।
Syntax
css
selector {
  text-shadow: h-offset v-offset blur color;
  text-overflow: ellipsis;
  word-wrap: break-word;
}

-webkit-text-stroke से Outlined Text

Non-standard लेकिन widely-supported -webkit-text-stroke property हर letter की glyph shape के चारों ओर एक outline draw करती है, text-shadow से अलग जो text के पीछे एक colored copy को blur करती है। यह एक width और color लेती है, और pure outline effect के लिए अक्सर एक transparent fill के साथ combine की जाती है।

Note:
  • Accepted values:
  • webkit-text-stroke-width — length, जैसे 1px
  • webkit-text-stroke-color — कोई भी color value
  • shorthand — जैसे 1px black
  • webkit-text-fill-color — transparent एक hollow outline देता है

उदाहरण: Outlined Text with -webkit-text-stroke

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

background-clip से Gradient Text

Gradient-filled text text element पर एक background gradient लागू करके, फिर एक transparent text color के साथ background-clip: text इस्तेमाल करके पाया जाता है ताकि gradient एक rectangular box भरने के बजाय letter shapes के through दिखे। यह eye-catching headings के लिए widely used trick है।

उदाहरण: Gradient Text with background-clip

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

Typographic Style के लिए Letter और Word Spacing

letter-spacing और word-spacing क्रमशः individual characters के बीच और words के बीच gap adjust करते हैं। Uppercase text पर wide letter-spacing headings और labels के लिए एक बहुत common stylistic choice है, जो default tight spacing के मुकाबले ज़्यादा spacious, deliberate, "designed" feel देता है।

Note:
  • Accepted values:
  • letter-spacing: normal | <length> — जैसे 2px या 0.1em (negative हो सकता है)
  • word-spacing: normal | <length> | <percentage> — words के बीच extra space
  • inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords

उदाहरण: Letter and Word Spacing for Typographic Style

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

Simple Underlines से आगे Text Decoration

text-decoration-style (solid, double, dotted, dashed, wavy) और text-decoration-thickness default पतली solid line से आगे underlines पर creative control देते हैं, जबकि text-underline-offset underline को text से और दूर ले जाता है ताकि यह "g" या "y" जैसे descenders को crowd न करे।

उदाहरण: 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>

Signature Heading Style के लिए Effects Combine करना

सबसे striking text treatments आमतौर पर इनमें से कई techniques को एक साथ combine करती हैं — एक gradient fill, एक subtle stroke, और deliberate letter-spacing साथ में — किसी अकेली property पर निर्भर रहने के बजाय।

ज़्यादातर CSS effects की तरह ही, restraint मायने रखती है: हर heading पर हर technique combine करना जल्दी ही polished के बजाय noisy लगने लगता है।

उदाहरण: 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. #}
आम गलतियां
  1. यह उम्मीद करना कि -webkit-text-stroke सिर्फ letters के बाहर draw होगा, जबकि stroke outline पर centered होता है और letter fill को पतला कर देता है।
  2. बिना color: transparent के background-clip: text इस्तेमाल करना जिससे gradient छुप जाता है।
  3. बहुत ज़्यादा letter spacing जोड़ना, जो words को पढ़ना मुश्किल बना देता है।
ब्राउज़र सपोर्ट

हर modern browser में supported: Chrome, Firefox, Safari, Edge और Opera। कुछ browsers में text stroke और gradient text (background-clip: text) अभी भी -webkit- prefix पर निर्भर करते हैं।

🔒

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.