CSS Icons
In this page:
Font Awesome Integration
Font Awesome सबसे widely used icon libraries में से एक है, जिसमें icons का एक विशाल catalog है। इसकी stylesheet link करना page पर कहीं भी simple class-based icons unlock कर देता है।
उदाहरण: Font Awesome Integration
<!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>
i { font-size: 2em; color: crimson; }
</style>
</head>
<body>
<i class="fa-solid fa-star"></i>
<i class="fa-solid fa-heart"></i>
<i class="fa-solid fa-home"></i>
</body>
</html>
Google Material Icons
Material Icons Google का अपना icon set है, जो Material Design की visual language follow करता है। यह Font Awesome जैसे ही काम करता है, लेकिन एक span के अंदर text की तरह plain English icon names इस्तेमाल करता है।
उदाहरण: Google Material Icons
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
.material-icons { font-size: 2em; color: teal; }
</style>
</head>
<body>
<span class="material-icons">favorite</span>
<span class="material-icons">star</span>
<span class="material-icons">home</span>
</body>
</html>
Bootstrap Icons
Bootstrap Icons एक lightweight icon library है जो naturally Bootstrap framework के साथ जुड़ती है, हालांकि यह standalone भी अच्छी तरह काम करती है, किसी empty element पर छोटे class names इस्तेमाल करके।
उदाहरण: Bootstrap Icons
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.min.css">
<style>
i { font-size: 2em; color: steelblue; }
</style>
</head>
<body>
<i class="bi bi-heart"></i>
<i class="bi bi-star"></i>
<i class="bi bi-house"></i>
</body>
</html>
Icons को Size और Color देना
क्योंकि icon library glyphs styled text characters की तरह render होते हैं, font-size और color जैसी सामान्य CSS properties सीधे control करती हैं कि वे कितने बड़े और किस color के दिखते हैं, किसी special icon-specific property की ज़रूरत नहीं।
उदाहरण: Sizing and Coloring Icons
<!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>
i {
font-size: 2em;
color: crimson;
}
</style>
</head>
<body>
<i class="fa-solid fa-star"></i>
</body>
</html>
Buttons के अंदर Icons
किसी button के अंदर एक icon को छोटे text label के साथ जोड़ना सबसे common icon use cases में से एक है, जो visitors को एक तेज़ visual cue और साफ़, readable text दोनों देता है।
उदाहरण: Icons Inside Buttons
<!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>
button {
display: flex;
align-items: center;
gap: 6px;
}
</style>
</head>
<body>
<button><i class="fa-solid fa-download"></i> Download</button>
</body>
</html>
- icon library की stylesheet link करना भूल जाना, जिससे icons खाली boxes या बिल्कुल कुछ नहीं की तरह render होते हैं।
- बिना किसी accessible label वाला icon इस्तेमाल करना, जिससे screen reader users को कोई अंदाज़ा नहीं होता कि वह क्या represent करता है।
- एक ही element पर conflicting class names वाली दो अलग libraries के icon classes को mix करना।
- Font Awesome, Material Icons, और Bootstrap Icons जैसी icon libraries एक linked stylesheet और simple class names के ज़रिए ready-made icons देती हैं।
- क्योंकि icon glyphs सिर्फ styled text characters हैं, font-size और color सीधे उनकी appearance control करते हैं।
- हमेशा icon-only elements को accessible text के साथ जोड़ें, जैसे एक aria-label, ताकि उनका meaning assistive technology के लिए खो न जाए।
Icon libraries standard font और stylesheet loading पर निर्भर करती हैं, इसलिए ये हर modern browser में काम करती हैं।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: