Advertisement
Beginner Next.js, Image & Font Optimization

How do you optimize custom fonts in a Next.js application using next/font?

Short answer

The next/font module lets you import fonts, including Google Fonts, directly into your project, automatically hosting the font files alongside your application and eliminating extra network requests to external font providers, while also preventing layout shift caused by fonts…

Save Next.js mock interview
Advertisement
AModel answer
The next/font module lets you import fonts, including Google Fonts, directly into your project, automatically hosting the font files alongside your application and eliminating extra network requests to external font providers, while also preventing layout shift caused by fonts loading late.
import { Inter } from 'next/font/google';

const inter = Inter({ subsets: ['latin'] });

export default function Layout({ children }) {
  return <html className={inter.className}><body>{children}</body></html>;
}
Real-world example
A company website switches to next/font for its Google Font, removing a noticeable flash of unstyled text and speeding up the page since the font no longer needs a separate external request.
Likely follow-ups
  • Does next/font work with fonts other than Google Fonts?
  • How does next/font help improve a website's Core Web Vitals scores?
Related topics