HTML आइकन फॉन्ट्स
In this page:
<link rel="stylesheet" href="icon-font.css">
<i class="icon-class"></i>
आइकन फॉन्ट्स क्या हैं?
icon font एक typeface है जहाँ हर character किसी letter या number की बजाय एक छोटे icon से मैप होता है। चूँकि icons बस font glyphs हैं, इन्हें साधारण text styling जैसे size, color, और shadow अपने आप मिल जाती है।
Font Awesome web पर सबसे लोकप्रिय icon font library है, जो icons का एक बड़ा catalog देती है और लाखों sites को power करती है।
उदाहरण: What Are Icon Fonts?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<i class="fa-solid fa-star"></i>
</body>
</html>
आइकन फॉन्ट लाइब्रेरी लिंक करना
ज़्यादातर icon fonts एक web font की तरह ही एक stylesheet और एक या ज़्यादा font files के रूप में distribute होते हैं। अपने document के head में stylesheet लिंक करने से पूरे page पर हर icon class उपलब्ध हो जाती है।
library चुनते समय: Font Awesome सबसे लोकप्रिय option है जिसमें अब तक का सबसे बड़ा icon set है, Google के Material Icons Google के अपने Material Design system को follow करते हैं और उन apps के लिए सही हैं जो पहले से Material Design पर बनी हैं, और Bootstrap Icons जानबूझकर हल्के हैं, जो उन projects के लिए अच्छे हैं जो पहले से Bootstrap framework इस्तेमाल कर रहे हैं।
उदाहरण: Linking an Icon Font Library
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<i class="fa-solid fa-heart"></i>
</body>
</html>
HTML में आइकन क्लासेस इस्तेमाल करना
icon fonts आमतौर पर एक base class और एक specific icon class के साथ, किसी खाली inline element पर लगाकर trigger किए जाते हैं। base class font family सेट करती है, जबकि specific class यह चुनती है कि कौन-सा character (icon) दिखाना है।
Google के Material Icons सीधे Google के Material Design system से लिए गए हैं, जो उन्हें Material Design guidance को follow करने वाले interfaces के लिए एक स्वाभाविक choice बनाता है।
उदाहरण: Using Icon Classes in HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<button>
<i class="fa-solid fa-trash"></i> Delete
</button>
</body>
</html>
CSS से आइकन्स को साइज़ और कलर करना
चूँकि icon font glyphs text characters हैं, font-size और color जैसी साधारण CSS properties यह control करती हैं कि हर icon कितना बड़ा और किस रंग का दिखे, बिना अलग icon image files की ज़रूरत के।
Bootstrap Icons जानबूझकर हल्के रखे गए हैं, जो उन्हें उन projects के लिए उपयुक्त बनाता है जो पहले से Bootstrap framework इस्तेमाल कर रहे हैं और एक बड़ी icon library जोड़ने से बचना चाहते हैं।
उदाहरण: Sizing and Coloring Icons with CSS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<i class="fa-solid fa-star" style="font-size: 2em; color: gold;"></i>
</body>
</html>
आइकन फॉन्ट्स के लिए एक्सेसिबिलिटी बातें
चूँकि icon fonts decorative characters के रूप में render होते हैं, screen readers इन्हें या तो skip कर सकते हैं या underlying character को गलत तरीके से पढ़ सकते हैं। एक text alternative देने से assistive technology इस्तेमाल करने वाले visitors के लिए icon का meaning बना रहता है।
उदाहरण: Accessibility Considerations for Icon Fonts
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
.sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
}
</style>
</head>
<body>
<button>
<i class="fa-solid fa-trash" aria-hidden="true"></i>
<span class="sr-only">Delete</span>
</button>
</body>
</html>
Chapter Quiz — Complete all 20 topics to unlock
0/20 topics done
Complete these topics first:
- HTML Keyboard Shortcuts
- HTML Browser Support
- HTML Character Sets
- HTML Doctypes
- HTML Audio/Video Reference
- HTML Meta Tags
- HTML ARIA Roles
- HTML Input Validation
- HTML Iframe Security
- HTML Responsive Images
- HTML Web Fonts
- HTML Icon Fonts
- HTML Progress & Meter
- HTML Output Element
- HTML Datalist
- HTML Image Maps
- HTML Browser DevTools
- HTML Validation
- HTML Quiz
- HTML Interview Prep