Self-hosting fonts
next/font self-hosts your fonts at build time. It removes the external network
request to a font provider, improves privacy and performance, and eliminates
layout shift.
For a Google font, import it from next/font/google, call it with options, and
apply the returned className:
import { Geist } from 'next/font/google';
const geist = Geist({ subsets: ['latin'] });
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" className={geist.className}>
<body>{children}</body>
</html>
);
}
The font file is downloaded and served from your own domain, so the browser never contacts Google. Next.js also generates a matching fallback font with adjusted metrics, so text does not jump when the real font loads.
For a font file you already have, import localFont from next/font/local and
point src at the file:
import localFont from 'next/font/local';
const myFont = localFont({ src: './my-font.woff2' });
Add the font in the root layout to apply it across the whole app.
In short: next/font self-hosts fonts from Google or a local file, so there are
no external requests and no layout shift.
You are about to answer a short quiz on next/font.