CSS-Font-Property
M2-R5.1 · Chapter 4: CSS · 2 min read
CSS Font Properties
CSS की Font Properties का उपयोग HTML elements के text की appearance, style, size और typeface को control करने के लिए किया जाता है।
इन properties की मदद से हम webpage के text को attractive और readable बना सकते हैं तथा पूरे webpage में consistent font style maintain कर सकते हैं।
Types of CSS Font Properties
Property | कार्य |
|---|---|
| Font का typeface निर्धारित करता है। |
| Text का size निर्धारित करता है। |
| Text का style निर्धारित करता है। |
| Text की thickness या boldness निर्धारित करता है। |
| Small-caps जैसी appearance देता है। |
| कई font properties को एक साथ set करता है। |
| Letters के बीच की दूरी नियंत्रित करता है। |
| Text lines की height नियंत्रित करता है। |
1. font-family Property
font-family property का उपयोग text का font या typeface निर्धारित करने के लिए किया जाता है।
Syntax:
p {
font-family: Arial, sans-serif;
}इसमें browser पहले Arial font उपयोग करने की कोशिश करेगा। यदि वह उपलब्ध नहीं है, तो sans-serif font का उपयोग किया जाएगा।
एक से अधिक fonts को comma , से separate किया जाता है।
p {
font-family: "Poppins", Arial, sans-serif;
}यहाँ "Poppins" उपलब्ध न होने पर browser अगले उपलब्ध font का उपयोग करने की कोशिश करेगा।
याद रखें: font-family → कौन-सा Font?
2. font-size Property
font-size property text का size निर्धारित करती है। इसकी मदद से text को छोटा या बड़ा किया जा सकता है।
Example:
p {
font-size: 18px;
}इससे paragraph का font size 18px होगा।
Common Units
Unit | Description | Example |
|---|---|---|
| Pixel-based size |
|
| Parent के font size के सापेक्ष |
|
| Root element के font size के सापेक्ष |
|
| Parent के font size के सापेक्ष |
|
| Viewport width के सापेक्ष |
|
उदाहरण के लिए, यदि parent element का font size 16px है, तो:
h1 {
font-size: 2em;
}इसका calculated size \(2 \times 16 = 32\text{px}\) होगा, बशर्ते कोई अन्य inheritance या sizing rule इसे प्रभावित न करे।
याद रखें: font-size → Text कितना बड़ा या छोटा?
3. font-style Property
font-style property text का style निर्धारित करती है।
इसके मुख्य values हैं:
Value | कार्य |
|---|---|
| सामान्य text |
| Italic style |
| तिरछा style |
Example:
p {
font-style: italic;
}इससे paragraph का text italic दिखाई देगा।
italic में font का designed italic version उपयोग हो सकता है, जबकि oblique सामान्यतः slanted style को दर्शाता है।
याद रखें: font-style → Text का Style
4. font-weight Property
font-weight property text की thickness या boldness निर्धारित करती है।
Common Values
Value | Description |
|---|---|
| सामान्य thickness |
| Bold text |
| Inherited weight से अपेक्षाकृत अधिक bold |
| Inherited weight से अपेक्षाकृत हल्का |
| सामान्य weight के बराबर |
| Bold weight के बराबर |
Example:
h1 {
font-weight: 700;
}
p {
font-weight: 400;
}CSS में numeric weights सामान्यतः 100 से 900 तक होते हैं। वास्तविक appearance उपलब्ध font family और उसके supported weights पर निर्भर करती है।
याद रखें: font-weight → Text कितना Bold या Light?
5. font-variant Property
font-variant property का उपयोग text को small-caps जैसी appearance देने के लिए किया जाता है।
small-caps
इसमें lowercase letters छोटे uppercase letters जैसे दिखाई देते हैं।
Example:
p {
font-variant: small-caps;
}Normal text:
Small-caps style:
This is a paragraph.
Small-caps appearance का उदाहरण
याद रखें: font-variant → Small Caps
6. font Shorthand Property
font एक shorthand property है, जिसकी मदद से कई font-related properties को एक ही declaration में set किया जा सकता है।
Syntax:
font: style variant weight size/line-height family;Example:
p {
font: italic small-caps bold 20px/30px Arial, sans-serif;
}इसमें:
italic→font-stylesmall-caps→font-variantbold→font-weight20px→font-size30px→line-heightArial, sans-serif→font-family
Important: Shorthand में font-size और font-family आवश्यक हैं। line-height optional है और इसे / के बाद लिखा जाता है।
7. letter-spacing Property
letter-spacing property letters के बीच की horizontal spacing को नियंत्रित करती है।
Example:
p {
letter-spacing: 2px;
}इससे text के characters के बीच अतिरिक्त spacing आ जाएगी।
Normal spacing
WELCOME TO CSS
Increased spacing
W E L C O M E T O C S S
याद रखें: letter-spacing → Letters के बीच की दूरी
8. line-height Property
line-height property text की प्रत्येक line के लिए line box की height निर्धारित करती है। इससे paragraphs की readability बेहतर बनाई जा सकती है।
Example:
p {
line-height: 1.8;
}यदि font size 18px है, तो line-height: 1.8 की calculated line height 32.4px होगी।
Normal line height
CSS makes webpages attractive. CSS controls the appearance of text and elements.
Increased line height
CSS makes webpages attractive. CSS controls the appearance of text and elements.
बढ़ी हुई line spacing का उदाहरण
याद रखें: line-height → Lines की height और उनके बीच की vertical spacing
Complete Example — All Font Properties
<!DOCTYPE html>
<html>
<head>
<title>CSS Font Properties</title>
<style>
p {
font-family: Arial, sans-serif;
font-size: 18px;
font-style: italic;
font-weight: 600;
font-variant: small-caps;
letter-spacing: 1px;
line-height: 1.8;
}
</style>
</head>
<body>
<h2>CSS Font Properties</h2>
<p>
This is an example of CSS font properties.
</p>
</body>
</html>Code की व्याख्या
Property | Value | कार्य |
|---|---|---|
|
| Font typeface set करता है। |
|
| Text का size set करता है। |
|
| Text को italic करता है। |
|
| Text की thickness निर्धारित करता है। |
|
| Small-caps appearance देता है। |
|
| Letters के बीच spacing बढ़ाता है। |
|
| Line box की height निर्धारित करता है। |