In Tailwind CSS v4 you add a font in your CSS, not in tailwind.config.js: a --font-* variable inside @theme creates a font-* class, and overriding --font-sans changes the font of the whole page. This guide covers both, plus adding your own font weights, loading the files (self-hosted, Google Fonts, Fontsource, next/font and Astro's font API) and the mistakes that leave you looking at Arial.
Every @theme snippet here was compiled with Tailwind 4.3.3, and the Astro setup was built with Astro 7.3.5.
Change the body font#
The page font in v4 comes from --font-sans. Preflight sets html { font-family: --theme(--default-font-family, …) }, and --default-font-family points at --font-sans. So to change the font of everything, override that one variable:
@import "tailwindcss";
@theme {
--font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
}That changes the body text, every element that inherits from it, and the font-sans class. You don't need font-sans on <body>, and you don't need a body { font-family } rule.
Keep a fallback stack after your font. If the file fails to load, or while it's still loading, the browser uses the next name in the list instead of its default serif.
Add a second font family#
Any --font-<name> variable becomes a font-<name> class. For a separate heading or display font:
@theme {
--font-display: "Geist", ui-sans-serif, sans-serif;
}<h1 class="font-display text-5xl font-semibold">…</h1>Compiled, font-display is just font-family: var(--font-display). The name is yours: font-heading, font-brand, font-code. To replace the monospace font used by <code> and <pre>, override --font-mono the same way you did --font-sans.
If the font name is only known at runtime (a CMS setting, for example), skip the theme and use a CSS variable directly: font-(family-name:--brand-font).
Add a custom font weight#
The nine weights from font-thin (100) to font-black (900) are --font-weight-* variables, so a new weight is one more line:
@theme {
--font-weight-book: 450;
}Now font-book sets font-weight: 450. For a one-off, font-[450] works without config. Two things decide whether you actually see the difference:
- With a variable font (one file covering a range such as 100–900), every weight in the range renders exactly.
- With static font files, the browser can only show the weights you loaded. Ask for 450 when you loaded 400 and 600, and you get 400. Load the files for the weights you use, and nothing else; each static weight is another download.
All nine default weights with what they're for are in our font size and weight cheat sheet.
OpenType features on the font#
A font variable can carry its own font-feature-settings, applied wherever the font is:
@theme {
--font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
--font-sans--font-feature-settings: "cv11", "ss01";
}For --font-sans this reaches the whole page through Preflight; for other families it's added to the font-<name> class. --font-sans--font-variation-settings works the same way for variable font axes.
Load the font files#
@theme only names the font. The browser still needs the files. Pick one of these.
Self-hosted with @font-face
Put the .woff2 files in your public folder and declare them at the top level of your CSS, outside @theme:
@import "tailwindcss";
@font-face {
font-family: "Inter Variable";
src: url("/fonts/InterVariable.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
font-display: swap;
}
@theme {
--font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
}font-weight: 100 900 tells the browser one file covers the whole range. font-display: swap shows the fallback font immediately and swaps when the file arrives, instead of invisible text. Preload the main file in your <head> if it's used above the fold: <link rel="preload" href="/fonts/InterVariable.woff2" as="font" type="font/woff2" crossorigin>.
Fontsource (npm)
Fontsource packages open-source fonts as npm modules with the @font-face rules included:
npm install @fontsource-variable/inter@import "tailwindcss";
@import "@fontsource-variable/inter";
@theme {
--font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
}The font name to use is in the package's README; for variable fonts it ends in "Variable".
Google Fonts
Either add the <link> tags Google gives you to your HTML <head>, or import the stylesheet in CSS. In CSS the @import url() has to come first, before @import "tailwindcss", because CSS ignores @import rules that follow other rules:
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap");
@import "tailwindcss";
@theme {
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
}The <link> in the head is faster (the browser finds it without first downloading your CSS), and self-hosting avoids a second domain altogether. For an EU audience self-hosting also avoids sending every visitor's IP address to Google.
Next.js with next/font
next/font downloads the font at build time and self-hosts it. Give it a CSS variable:
// app/layout.tsx
import { Inter } from "next/font/google"
const inter = Inter({ subsets: ["latin"], variable: "--font-inter" })
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" className={inter.variable}>
<body>{children}</body>
</html>
)
}Then point Tailwind at that variable, using @theme inline:
@import "tailwindcss";
@theme inline {
--font-sans: var(--font-inter), ui-sans-serif, system-ui, sans-serif;
}inline matters here. Without it, Tailwind defines --font-sans: var(--font-inter) on :root, where --font-inter doesn't exist (next/font sets it on <html> through the class). With inline, the font-sans class uses the value directly and the variable resolves where it's used.
Astro's font API
Since Astro 6, fonts are part of the config. Astro downloads the files at build time, self-hosts them, and generates a size-adjusted fallback font so the page doesn't jump when the real one loads:
// astro.config.mjs
import { defineConfig, fontProviders } from "astro/config"
export default defineConfig({
fonts: [
{
provider: fontProviders.google(),
name: "Inter",
cssVariable: "--font-inter",
weights: [400, 600],
styles: ["normal"],
subsets: ["latin"],
},
],
})---
// src/layouts/Base.astro
import { Font } from "astro:assets"
---
<head>
<Font cssVariable="--font-inter" preload />
</head>@theme inline {
--font-sans: var(--font-inter), ui-sans-serif, system-ui, sans-serif;
}Set styles explicitly. In our build, leaving it out produced italic files for every weight as well, which doubles the download if you never use italics.
Why is my custom font not working?#
The usual causes, in the order we'd check them:
- The name doesn't match. The name in
--font-sansmust be exactly thefont-familyin the@font-facerule (or the provider's name), including "Variable" and capitals. DevTools, Computed,font-family, then the "Rendered fonts" panel shows what the browser actually used. - **The
@font-faceis inside@theme.**@themeonly takes variables. Put@font-faceat the top level. - **
@import url()comes after@import "tailwindcss".** The browser drops it silently. Move it to the first line. - **
var()in@themewithoutinline.** Withnext/fontor Astro's<Font>, the variable lives on<html>, not:root. Use@theme inline. - **A v3
tailwind.config.jsthat isn't loaded.** v4 doesn't read it unless you add@config "./tailwind.config.js";. Better: move the values to@theme. Our config to v4 converter does that forfontFamily,fontWeightand the rest oftheme.extend. - The file 404s. The Network tab, filtered to Font, shows it. Paths in
url()are relative to the CSS file unless they start with/.
FAQ#
How do I change the default font in Tailwind v4?
Override --font-sans in @theme: @theme { --font-sans: "Inter", ui-sans-serif, sans-serif; }. Preflight uses it for the whole page, so no class on <body> is needed. Load the font files separately.
Where is tailwind.config.js in Tailwind v4?
There isn't one by default. Fonts, colours, breakpoints and the rest are CSS variables in an @theme block in your main CSS file. A v3 config still works if you load it with @config, but new projects don't need it.
How do I add a custom font weight in Tailwind v4?
Add --font-weight-<name>: <value>; to @theme, for example --font-weight-book: 450;, which creates font-book. Or use font-[450] once. The font itself has to support that weight.
What is the default font in Tailwind CSS?
The system font of each device. In Tailwind 4.3 --font-sans is -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', Arial, sans-serif plus emoji fonts: San Francisco on Apple devices, Segoe UI on Windows, Roboto on Android. Earlier v4 releases started the stack with ui-sans-serif, system-ui, which gives the same fonts on most systems. font-serif and font-mono use system stacks too.

