Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Web Fonts – Google Fonts & @font-face | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 26 of 55

·HTML

Web Fonts – Google Fonts & @font-face

9 min

Course progress47%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Linking Google Fonts via a `<link>` tag and customizing `display`
  • Self‑hosting fonts with `@font-face` and proper format fallbacks
  • Performance tips: preconnect, `font-display`, subsetting
  • Choosing appropriate font formats (`woff2`, `woff`)
  • Providing a reliable fallback stack

Adding Custom Fonts

Google Fonts (external)

<link href='https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap' rel='stylesheet' />
body { font-family: 'Roboto', sans-serif; }

Self‑hosted fonts (@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; }

Performance considerations

  • Preconnect to 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).
  • Serve only the character subsets you need (e.g., latin, cyrillic) to reduce download size.
  • When self‑hosting, compress fonts and use woff2 as the primary format.

Quick checklist for fonts

  1. Font loaded via <link> or @font-face? ✅
  2. font-display set to swap or fallback? ✅
  3. Fallback font stack defined (font-family: 'MyFont', Arial, sans-serif;)? ✅
  4. Preconnect added for external font providers? ✅
  5. Unused character subsets removed? ✅

Tip: Use the Font‑source Chrome extension to see which fonts are being downloaded and their sizes.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
Previous lessonOpen Graph & Twitter Card TagsContinue to lesson 27Progressive Enhancement – Feature DetectionBack to HTML Course curriculum