网页 综合 更新时间 2026-05-27 00:00:00

Font Optimization

自动蜘蛛 nextjs.org 正文约 1644 字
Font Optimization
The next/font module automatically optimizes your fonts and removes external network requests for improved privacy and performance.
It includes built-in self-hosting for any font file. This means you can optimally load web fonts with no layout shift.
To start using next/font, import it from next/font/local or next/font/google, call it as a function with the appropriate options, and set the className of the element you want to apply the font to. For example:
Fonts are scoped to the component they're used in. To apply a font to your entire application, add it to the Root Layout.
You can automatically self-host any Google Font. Fonts are included as static assets and served from the same domain as your deployment, meaning no requests are sent to Google by the browser when the user visits your site.
To start using a Google Font, import your chosen font from next/font/google:
We recommend using variable fonts for the best performance and flexibility. But if you can't use a variable font, you will need to specify a weight:
To use a local font, import the localFont function from next/font/local and specify the src of your local font file. The path is resolved relative to the file where localFont is called. Fonts can be stored anywhere in the project, including the public folder or co-located inside the app folder. For example, to use a font stored in app/fonts/:
If you want to use multiple files for a single font family, src can be an array:
See the API Reference for the full feature set of Next.js Font
Last updated May 27, 2026
Subscribe to our newsletter
Stay updated on new releases and features, guides, and case studies.
访问原文 返回搜索 https://nextjs.org/docs/app/getting-started/fonts
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。