Next.js › Image & Font Optimization
How do you optimize custom fonts in a Next.js application using next/font?
BeginnerAnswer
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.