Skip to content

Tailwind v4 custom fonts: how to add Google or local fonts

Add @fontsource or next/font in Tailwind CSS v4 with @theme and @theme inline, plus the three reasons a custom font silently falls back to system-ui.

Updated 3 December 2026Tested with
  • Tailwind CSS 4.3.5
  • Next.js 16.4.6

In Tailwind CSS v4, custom fonts are declared in CSS with @theme instead of tailwind.config.js. Set --font-sans, --font-serif or --font-mono to override the defaults, or add your own name like --font-display to get a font-display utility. If your font silently falls back to the system face, the cause is almost always @theme vs @theme inline with next/font, or a missing stylesheet import.

Option 1: @fontsource or local WOFF2 (Vite, Astro, plain CSS)

Install a variable font package (self-hosted, zero third-party requests) and import it before your Tailwind CSS file:

npm install @fontsource-variable/inter
src/styles/global.cssCSS
@import "@fontsource-variable/inter";@import "tailwindcss"; @theme {  --font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;  --font-display: "Instrument Serif", Georgia, serif;}

That immediately updates font-sans across the whole site and creates a new font-display utility class.

Option 2: next/font in Next.js (use @theme inline)

next/font/google exposes a CSS variable on <html> (for example --font-geist-sans). In Tailwind v4, referencing another CSS variable inside @theme requires @theme inline:

app/layout.tsxTSX
import { Geist, Geist_Mono } from "next/font/google"; const geistSans = Geist({ subsets: ["latin"], variable: "--font-geist-sans" });const geistMono = Geist_Mono({ subsets: ["latin"], variable: "--font-geist-mono" }); export default function RootLayout({ children }: { children: React.ReactNode }) {  return (    <html lang="en" className={`${geistSans.variable} ${geistMono.variable}`}>      <body className="font-sans antialiased">{children}</body>    </html>  );}
app/globals.cssCSS
@import "tailwindcss"; @theme inline {  --font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif;  --font-mono: var(--font-geist-mono), ui-monospace, monospace;}

Three reasons a custom font silently fails

  1. Step 1: Self-referencing variable name

    Writing variable: "--font-sans" in next/font and --font-sans: var(--font-sans) in @theme makes the variable invalid in CSS. Name the loader variable --font-inter and map --font-sans: var(--font-inter) inside @theme inline.

  2. Step 2: Google Fonts @import placed after @import "tailwindcss"

    CSS requires every external @import url(...) to sit at the very top of the file, before @import "tailwindcss";. Better yet, load Google Fonts with a <link rel="stylesheet"> in <head> or self-host with @fontsource so it never blocks CSS parsing.

  3. Step 3: Font-family string doesn't match @font-face

    Variable Fontsource packages register "Inter Variable", not "Inter". Open DevTools › Computed › Rendered Fonts to see whether the browser actually loaded your face or fell back to system-ui.

Questions

Do I still need tailwind.config.js for fonts in v4?

No. Everything that lived under theme.extend.fontFamily in v3 is now a --font-* variable inside @theme. See Does Tailwind CSS v4 have a config file?

How do I preload a local font for faster LCP?

Add <link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin /> in <head> for the single primary body or heading weight used above the fold. Preloading too many weights slows down the first paint instead of helping it.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.