---
title: "How do I add Google Fonts in Next.js without layout shift?"
description: "Use next/font/google. It downloads the font at build time, serves it from your own domain and creates a size-matched fallback so text does not jump when the font loads."
url: https://www.danny.engineering/answer/nextjs/how-do-i-add-google-fonts-in-nextjs-without-layout-shift
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["Next.js"]
---

# How do I add Google Fonts in Next.js without layout shift?

## The short answer


Do not add a `<link>` to [fonts.googleapis.com](http://fonts.googleapis.com/). Import the font from `next/font/google`, call it once at module level, and apply its class or CSS variable in your root layout. Next.js self-hosts the files and generates a fallback font with matching metrics, so the page does not shift when the real font arrives.


```typescript
// app/layout.tsx
import { Inter } from 'next/font/google';

const inter = Inter({ subsets: ['latin'], display: 'swap' });

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" className={inter.className}>
      <body>{children}</body>
    </html>
  );
}
```


## Why it happens


With a normal web font, the browser first paints text in a fallback such as Arial, then swaps in the web font once it downloads. The two fonts have different widths and line heights, so lines rewrap, headings grow or shrink, and content below moves. That movement counts towards Cumulative Layout Shift (CLS), one of the Core Web Vitals. Loading the CSS from Google adds another delay, because the browser has to connect to two extra domains before it even knows which font files to fetch.


`next/font` fixes both problems:

- The CSS and font files are downloaded at build time and served with your other static assets. The browser sends no requests to Google.
- The font is preloaded on the routes that use it.
- With `adjustFontFallback` (on by default), Next.js writes a fallback `@font-face` rule with size adjustments so the fallback takes up almost the same space as the real font. When the swap happens, very little moves.

## How to fix it


### Use a variable font where you can


Variable fonts such as Inter, Roboto Flex or Geist need no `weight` option and cover every weight in one file. For a font that is not variable, list the weights you use.


```typescript
import { Roboto } from 'next/font/google';

const roboto = Roboto({
  weight: ['400', '700'],
  style: ['normal', 'italic'],
  subsets: ['latin'],
});
```


Font names with spaces use underscores in the import: `Roboto_Mono`, `Source_Sans_3`.


### Expose fonts as CSS variables


When you use more than one font, or style with Tailwind, set the `variable` option and put the variables on `<html>`.


```typescript
// app/fonts.ts
import { Inter, JetBrains_Mono } from 'next/font/google';

export const sans = Inter({ subsets: ['latin'], variable: '--font-inter' });
export const mono = JetBrains_Mono({ subsets: ['latin'], variable: '--font-jetbrains-mono' });
```


```typescript
// app/layout.tsx
import { sans, mono } from './fonts';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" className={`${sans.variable} ${mono.variable}`}>
      <body>{children}</body>
    </html>
  );
}
```


Then use the variables in CSS. With Tailwind CSS v4, map them in `@theme inline`:


```css
@import 'tailwindcss';

@theme inline {
  --font-sans: var(--font-inter);
  --font-mono: var(--font-jetbrains-mono);
}
```


Give the `next/font` variables their own names, such as `--font-inter`, rather than reusing Tailwind's `--font-sans`, so the theme token never points at itself. The `font-sans` and `font-mono` utilities now use your fonts, and Tailwind's base styles apply `font-sans` to the page by default.


### Local font files


For a licensed or custom font, use `next/font/local` with a path relative to the file that calls it.


```typescript
import localFont from 'next/font/local';

export const brand = localFont({
  src: './fonts/Brand-Variable.woff2',
  variable: '--font-brand',
});
```


### Choose display: optional for zero swap


The default `display` value is `swap`. If you would rather never see a swap, `display: 'optional'` lets the browser keep the fallback for that page view when the font is slow. The font is cached for the next page.


## Common pitfalls

- **Calling the font function in many files.** Each call creates a separate font instance. Define fonts once in a shared file such as `app/fonts.ts` and import the objects.
- **Calling it inside a component.** Font loaders must be called at module scope and assigned to a constant.
- **Forgetting subsets.** With preloading on, Next.js warns if you do not say which subsets to preload. `['latin']` is the usual choice.
- **Keeping the old link tag.** If a Google Fonts `<link>` or `@import` is still in your CSS, you download the font twice and lose the benefit.
- **Turning off adjustFontFallback.** Without it, the fallback has no size adjustments and the shift comes back.
- **Loading too many families.** Each family and weight is another download. Two families is plenty for most sites.

## Related reading

- [Next.js: Font module](https://nextjs.org/docs/app/api-reference/components/font)
- [MDN: font-display](https://developer.mozilla.org/docs/Web/CSS/@font-face/font-display)
