Lesson 26 of 55
HTMLWeb Fonts – Google Fonts & @font-face
9 min
Course progress47%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 26 of 55
HTML9 min
Keep these ideas in mind as you work through the lesson.
<link href='https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap' rel='stylesheet' />
body { font-family: 'Roboto', sans-serif; }
@font-face)@font-face {
font-family: 'MyFont';
src: url('fonts/MyFont.woff2') format('woff2'),
url('fonts/MyFont.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap; /* Show fallback while font loads */
}
body { font-family: 'MyFont', serif; }
fonts.gstatic.com for faster Google Font loading:<link rel='preconnect' href='https://fonts.gstatic.com' crossorigin>
font-display: swap shows a fallback font while the custom font loads, preventing flash of invisible text (FOIT).latin, cyrillic) to reduce download size.woff2 as the primary format.<link> or @font-face? ✅font-display set to swap or fallback? ✅font-family: 'MyFont', Arial, sans-serif;)? ✅Tip: Use the Font‑source Chrome extension to see which fonts are being downloaded and their sizes.