Apply a bundled brand typeface across the application
Branding
Next.js 16+ · Module
next/font/local loads local font files through Next.js's font optimization system. It self-hosts the assets and returns generated font styling values that can be applied to elements.
Import the default localFont function, provide one or more local font files through src, and apply the returned font object's generated className or variable to an element. Next.js self-hosts and optimizes the font during the build.
import localFont from 'next/font/local'
const font = localFont({ src: './font.woff2' })| Name | Type | Description |
|---|---|---|
src | string | FontSource[] | One font file path, or an array of font file configurations for a family. |
display | FontDisplay | Controls the CSS font-display behavior. |
variable | string | Optional CSS custom property name generated for the font. |
declarations | FontDeclarations | Optional explicit family name and other font-face declarations. |
A font object exposing generated styling values such as className, variable, and style.
import localFont from 'next/font/local'
const geist = localFont({
src: './fonts/GeistVF.woff2',
display: 'swap',
})
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en" className={geist.className}>
<body>{children}</body>
</html>
)
}This loads a local font and applies the generated class to the root HTML element.
Branding
Performance
Typography variants
next/font/local provide?localFont is the default export from next/font/local. It accepts font configuration, including a required src, and returns a font object whose generated className can be applied to an element.
Follow-up: How should the same font be used in several places? Load it once in a shared module and import that font object wherever it is needed.
The path in src is resolved relative to the file that calls localFont. Font files may be stored in locations such as the public folder or alongside files in the app directory.
Follow-up: What changes if the font file moves? Update the relative src path from the calling module; the path is not resolved relative to the project root.
A single family can use multiple files by passing an array to src. The returned font object can then be applied through its generated CSS class or other exposed values.
Follow-up: Why might multiple files be necessary? Separate files can represent different weights or styles within the same family, allowing the browser to select the appropriate face.
next/fontnext/font/googlefont.classNamefont.variablefont.style