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.
- 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/interpnpm add @fontsource-variable/interyarn add @fontsource-variable/interbun add @fontsource-variable/inter@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:
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> );}@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
Step 1: Self-referencing variable name
Writing
variable: "--font-sans"innext/fontand--font-sans: var(--font-sans)in@thememakes the variable invalid in CSS. Name the loader variable--font-interand map--font-sans: var(--font-inter)inside@theme inline.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@fontsourceso it never blocks CSS parsing.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.
Related articles
- Tailwind CSS v4Does Tailwind CSS v4 have a config file?Not by default: v4 is configured in CSS with @theme. Where every v3 setting went, how to load an old tailwind.config.js with @config, and when to keep it.
- Tailwind CSS v4Tailwind v4 custom colors: how to add them, and why they don’t workAdd a --color-* variable in @theme and every colour utility follows. The four reasons a custom colour silently does nothing, each reproduced.
- UI designFont pairing for websites: practical rules that hold upPractical font pairing rules for websites: when one family beats two, contrasting serif and sans, matching x-height, monospace for data, and five tested pairs.
Still stuck? We answer every message ourselves. Write to us