Web Fonts and Icons
๐ Covered in this chapter:
Google Fonts ยท Local Fonts ยท Font Loading ยท Icon Fonts ยท SVG Icons ยท Accessibility ยท aria-hidden ยท Icon Buttons ยท Fallback ยท Performance
Welcome to Chapter 18: Web Fonts and Icons โ part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1Google Fonts & Local Fonts
HTML โ Google Fontsโถ Try in Editor
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
</style>
Local fonts โ self-host for privacy, GDPR, and faster CDN control. @font-face with font-display: swap.
2SVG Icons vs Icon Fonts
Icon fonts (Font Awesome) โ legacy, accessibility issues. SVG icons โ modern standard, scalable, style with CSS.
HTML โ Accessible Icon Button
<button type="button" aria-label="Close dialog">
<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24">
<path d="M6 6l12 12M18 6L6 18" stroke="currentColor"/>
</svg>
</button>
aria-hidden="true" โ decorative icons screen readers skip chestayi. Meaningful icons ki aria-label on button mandatory.
3Performance & Fallback Icons
- Preload only critical font weights (400, 600)
- SVG inline for above-fold icons โ no extra request
- Fallback: Unicode symbols or text label if icon fails
- Icon sprite sheets for many repeated icons