Usage
Pure CSS
You can use Nuxt Fonts with pure CSS by adding font-family declarations to your CSS:
div {
font-family: 'Inter', sans-serif;
}
font-family declaration. Subsequent fonts in the list will be used to generate metrics for font fallbacks.font-family within your <template> don't work; only CSS stylesheets are processed. See when a font isn't picked up.When a font isn't picked up
Nuxt Fonts resolves fonts by scanning the CSS your project generates for font-family declarations. A font that's never named in that CSS is never resolved, so no @font-face rule is emitted and the browser falls back to a system font.
Common places a font stays invisible to the scan:
- a
styleattribute in a template, or any other inline style - a
font-familyinside an SVG, whether served frompublic/or imported as an asset - a Tailwind v4
--font-*theme variable declared with@theme inlinethat no utility uses, which Tailwind drops before Nuxt Fonts sees it - a font named only at runtime, such as a family a user chooses and you apply through a CSS variable
- a font set by CSS-in-JS, a third-party stylesheet, or a framework preset that isn't part of your own CSS
For all of these, declare the family with global: true and Nuxt Fonts emits its @font-face rules whether or not it finds a use for them:
export default defineNuxtConfig({
fonts: {
families: [
{ name: 'Anton', provider: 'google', global: true },
],
},
})
You can then use font-family: 'Anton' anywhere, including in places Nuxt Fonts never scans.
Tailwind CSS
With Tailwind CSS you specify fonts using a CSS variable:
@theme {
--font-display: "Inter", "sans-serif";
}
Overriding Tailwind's default font family works too, including via @theme inline, which compiles --font-sans down to --default-font-family:
@theme {
--default-font-family: "Inter", sans-serif;
}
--font-* theme variable that is never used by a utility (and is declared with @theme inline) is removed by Tailwind before Nuxt Fonts sees it. Use the utility at least once, declare it with @theme static, or set the font in fonts.families with global: true.processCSSVariables to true for Tailwind v4 support, it is no longer needed or recommended for v0.11.0 and above.UnoCSS
You can use Nuxt Fonts with UnoCSS by setting fontFamily in your configuration file:
import { defineConfig } from 'unocss'
export default defineConfig({
theme: {
fontFamily: {
inter: 'Inter',
},
},
})
If you're using the Wind4 (Tailwind4) preset, set font instead of fontFamily.
font: {
inter: 'Inter',
},