CSS Fonts
In this page:
selector {
font-family: "Font Name", fallback-family;
font-size: length;
font-weight: normal | bold | number;
font-style: normal | italic;
}
font-family और Fallback Fonts
font-family बताता है कि कौन-सा typeface(s) इस्तेमाल करना है, preference के order में। अगर पहली choice visitor की device पर available नहीं है, तो browser list की अगली वाली try करता है, sans-serif या serif जैसे generic fallback पर खत्म होते हुए।
- हमेशा किसी font-family list को एक generic fallback पर खत्म करें, यह guarantee करता है कि हर named font load न होने पर भी text readable बना रहे।
- Accepted values:
- font-family — comma-separated list; spaces वाले names को quote करें, जैसे "Open Sans"
- serif | sans-serif | monospace — सबसे common generic fallbacks
- cursive | fantasy — decorative generic families
- system-ui — operating system का UI font
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: font-family and Fallback Fonts
<style>
p {
font-family: "Segoe UI", Arial, sans-serif;
}
</style>
<p>Falls back through the list if a font isn't available</p>
font-size और font-weight
font-size तय करता है कि text कितना बड़ा render होता है, और font-weight तय करता है कि वह कितना bold दिखता है, thin (100) से लेकर normal (400) होते हुए bold (700) और उससे आगे तक।
- जहाँ possible हो font-size के लिए rem units इस्तेमाल करें, ये page की base font size के relative consistently scale होते हैं और visitor की browser settings का सम्मान करते हैं।
- Accepted values:
- length — जैसे 16px, 1.25rem, 1.5em
- keyword — xx-small से xx-large (medium default है)
- larger | smaller — parent के size के relative
- percentage — parent की font size के relative
- font-weight: normal (400), bold (700), या 1 से 1000 तक कोई number
- font-weight: lighter | bolder — parent के relative
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: font-size and font-weight
<style>
p {
font-size: 20px;
font-weight: 700;
}
</style>
<p>Large, bold text</p>
font-style और font-variant
font-style italics toggle करता है, सबसे common रूप से normal या italic। font-variant extra typographic options देता है, सबसे ख़ास तौर पर small-caps, जो lowercase letters को छोटे uppercase letters की तरह render करता है।
- Italics को कम मात्रा में इस्तेमाल करें, emphasis या citations के लिए, क्योंकि इन्हें ज़्यादा इस्तेमाल करना text को जल्दी scan करना मुश्किल बना सकता है।
- Accepted values:
- normal — upright text (initial value)
- italic — font का italic face
- oblique — slanted; एक angle ले सकता है
- font-variant: normal | small-caps
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: font-style and font-variant
<style>
em {
font-style: italic;
}
.caps {
font-variant: small-caps;
}
</style>
<p><em>Italic emphasis</em></p>
<p class="caps">Small caps text</p>
Shorthand font Property
font shorthand style, weight, size, और family को एक declaration में combine करता है। Size और family ज़रूरी हैं, उसी order में, value के अंत के पास।
- एक बार जब आप individual font properties में सहज हो जाएँ तो shorthand काम की है, लेकिन सीखते समय longhand versions अक्सर ज़्यादा साफ़ होते हैं।
- Accepted values:
- font-size — ज़रूरी, जैसे 16px
- font-family — ज़रूरी, आख़िर में आता है
- font-style / font-variant / font-weight — optional, size से पहले
- line-height — optional, size और एक slash के बाद, जैसे 16px/1.5
- system fonts — caption, menu, status-bar और दूसरे
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: Shorthand font Property
<style>
p {
font: italic bold 18px "Segoe UI", sans-serif;
}
</style>
<p>Style, weight, size, and family in one line</p>
Google Fonts और Web Safe Fonts
'Web safe' fonts (जैसे Arial, Georgia, और Verdana) लगभग हर device पर पहले से installed हैं, इसलिए ये बिना किसी extra loading के reliably render होते हैं। Google Fonts एक free service है जो आपको उस safe list से आगे custom typefaces load करने देती है।
उदाहरण: Google Fonts and Web Safe Fonts
<style>
.safe {
font-family: Arial, Georgia, Verdana, sans-serif;
}
</style>
<p class="safe">Web safe fonts render reliably with no extra loading</p>
- font-family में सिर्फ एक font specify करना, बिना किसी fallback के अगर वह font load न हो पाए।
- एक ऐसी font-weight value इस्तेमाल करना जिसे loaded font file असल में support नहीं करती, जिसे browsers fake कर सकते हैं या नज़रअंदाज़ कर सकते हैं।
- font-family में उस font name को reference करने से पहले Google Fonts stylesheet link करना भूल जाना।
- font-family, font-size, font-weight, और font-style text typography के core building blocks हैं।
- हमेशा किसी font-family list के अंत में एक generic fallback (जैसे sans-serif) list करें।
- Google Fonts और दूसरी font services आपको standard web safe fonts से आगे custom typefaces इस्तेमाल करने देती हैं।
Standard CSS font properties हर modern browser में supported हैं; Google Fonts वहाँ काम करता है जहाँ भी कोई browser external stylesheet load कर सकता है।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: