Skip to content

Custom Font Not Loading

Quick summary

Your custom font is not loading because the font file path is wrong, the format is incorrect, or the font-face declaration has errors.

Why this happens

  • Wrong URL path to the font file in the src property

  • Missing or incorrect font-format declaration

  • The font file is not deployed or is in the wrong directory

  • CORS issues when loading fonts from a different domain

Minimal example

✗ Broken code
@font-face {
  font-family: 'MyFont';
  src: url('/fonts/myfont.ttf'); /* Wrong path or format */
}
body { font-family: 'MyFont'; }
✓ Fixed code
@font-face {
  font-family: 'MyFont';
  src: url('/fonts/myfont.woff2') format('woff2'),
       url('/fonts/myfont.woff') format('woff');
  font-display: swap;
}
body { font-family: 'MyFont', sans-serif; }

Fix the font path, use modern woff2 format with woff fallback, add font-display: swap for better loading behavior, and include a fallback font.

How to diagnose

  • Check the Network tab for 404 errors on font files

  • Verify the @font-face src URL matches the actual file location

  • Check the browser console for CORS errors on font files

  • Inspect the computed font-family — is your custom font listed?

How to fix

  • Correct the src URL path to the font file

  • Add the correct format() hint: format('woff2'), format('woff'), etc.

  • Add CORS headers if loading fonts from a CDN or different origin

  • Use a fallback font stack: font-family: 'MyFont', sans-serif

How to prevent

  • Use Google Fonts or a font CDN to avoid path and format issues

  • Preload critical fonts: <link rel='preload' href='font.woff2' as='font' type='font/woff2' crossorigin>

  • Always specify a fallback font in the font-family stack

Related Resources

Related Glossary

Related Lessons

  • CSS

    Learn CSS including fonts.

← Back to language