Skip to content
Dashboard

Custom fonts without compromise using Next.js and `next/font`

Highly optimized, self-hosted fonts with just a few lines of code.

Get started

This Next.js 13 template, with `next/font` ready to go in `pages/index.js`, can give you a jumpstart on conquering layout shift.

Deploy

Link to headingBefore next/font

components/head.tsx
<script
dangerouslySetInnerHTML={{
__html: `
if (!window.newVisit && document.cookie && document.cookie.indexOf('beenHere=1') !== -1) {
document.documentElement.classList.add('inter')
} else {
window.newVisit=true
}
setTimeout(function() {
document.cookie='beenHere=1;samesite=lax;expires='+
new Date(Date.now()+31*3600*24*1000).toGMTString()
})`,
}}
/>
<link
as="font"
crossOrigin="anonymous"
href="https://assets.vercel.com/raw/upload/v1660068731/fonts/4/Inter.var.latin.woff2"
rel="preload"
type="font/woff2"
/>

Custom font solution used by Vercel before `next/font`.

:root {
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
}
:root.inter {
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
}

Custom font CSS used by Vercel before `next/font`.

@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 100 900;
font-display: optional;
src: url('https://assets.vercel.com/raw/upload/v1660068731/fonts/4/Inter.var.latin.woff2')
format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212,
U+2215, U+FEFF, U+FFFD;
}
/* Plus eight more @font-face definitions for other languages and characters. */

@font-face rules to manually subset the font before we used `next/font`.

Link to headingEnter next/font

lib/font.ts
import { Inter } from 'next/font/google';
const interFont = Inter({
display: 'swap',
subsets: ['latin'],
variable: '--font-sans',
});
export const interFontClass = interFont.variable;

The current code for Vercel's custom fonts is drastically reduced with `next/font`.

Learn how to use `next/font` in Next.js 13, for both local and remote fonts from Google.

Link to headingBring your own fonts

Want to talk to an expert?

Brainstorm with our team about your unique use case of Next.js.

Send us a message