May 29, 2025
Tailwind CSS
Next.js
How to Use Google Fonts with Tailwind CSS and Next.js
Overview
While styling the typography for my portfolio project, I wanted to use Google Fonts with Tailwind CSS and Next.js. I used next/font/google to load the Inter font, but I wasn’t sure how to make it available as a Tailwind class like font-inter, or how to set it as the default font across the site.
After experimenting and reviewing the Tailwind v4 approach, I was able to clarify the roles of className, variable, and @theme in making fonts reusable and customizable.
This setup allowed me to apply Inter site-wide while keeping Tailwind classes semantic and reusable.
What I Learned
-
next/font/google
- Use in layout.tsx to load fonts at build time
- The
classNameproperty can be used for scoped application - The
variableproperty defines a CSS variable like--font-interfor use in Tailwind or custom styles
-
Tailwind + CSS Variables
@theme { --font-inter: var(--font-inter); }is needed to makefont-interusable as a class@theme inline { --font-sans: var(--font-inter); }lets me replace Tailwind’s default font forfont-sans
-
Best Practices
- Use
classNamewhen the font is only needed in a specific component - Use
variable+@themewhen the font should be shared across Tailwind classes or used as the default - For global fonts, map to
--font-sansso that Tailwind's default typography utilities pick it up
- Use
