Skip to main content

Overview

Nuxt UI automatically integrates @nuxt/fonts to provide optimized font loading and management. The module handles font optimization, local font loading, and web font providers.

Automatic Integration

The @nuxt/fonts module is automatically installed and configured by Nuxt UI:
// Automatically configured by Nuxt UI
{
  fonts: {
    defaults: {
      weights: [400, 500, 600, 700]
    }
  }
}
Font integration is enabled by default. You can disable it by setting fonts: false in your Nuxt UI configuration.

Default Font Weights

Nuxt UI pre-configures common font weights used throughout the component library:
  • 400 - Regular text
  • 500 - Medium emphasis
  • 600 - Semibold headings
  • 700 - Bold elements

Using System Fonts

By default, Nuxt UI uses system font stacks for optimal performance:
font-family: ui-sans-serif, system-ui, sans-serif;
No additional configuration is needed for system fonts.

Custom Fonts

Google Fonts

Add Google Fonts to your application:
1

Configure in nuxt.config.ts

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxt/ui'],
  
  fonts: {
    families: [
      { name: 'Inter', provider: 'google' }
    ]
  }
})
2

Apply in CSS

app.vue
<style>
body {
  font-family: 'Inter', sans-serif;
}
</style>

Local Fonts

Use local font files for better performance and privacy:
1

Add font files

Place your font files in the public/fonts directory:
public/fonts/MyFont-Regular.woff2
public/fonts/MyFont-Bold.woff2
2

Configure local fonts

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxt/ui'],
  
  fonts: {
    families: [
      {
        name: 'MyFont',
        provider: 'local',
        weights: [400, 700]
      }
    ]
  }
})
3

Apply the font

body {
  font-family: 'MyFont', sans-serif;
}

Font Display Strategy

Optimize font loading behavior:
nuxt.config.ts
export default defineNuxtConfig({
  fonts: {
    defaults: {
      weights: [400, 500, 600, 700],
      fallbacks: {
        'sans-serif': ['system-ui', 'Arial']
      }
    }
  }
})
{
  fonts: {
    defaults: {
      styles: ['normal'],
      display: 'swap'
    }
  }
}

Variable Fonts

Use variable fonts for greater flexibility:
nuxt.config.ts
export default defineNuxtConfig({
  fonts: {
    families: [
      {
        name: 'Inter Variable',
        provider: 'google',
        variable: true
      }
    ]
  }
})

Disabling Font Module

If you prefer to manage fonts manually, disable the automatic integration:
nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxt/ui'],
  
  ui: {
    fonts: false
  }
})

Tailwind Typography

Combine custom fonts with Tailwind’s typography plugin for content-rich pages:
tailwind.config.ts
export default {
  theme: {
    extend: {
      fontFamily: {
        sans: ['Inter', 'sans-serif'],
        mono: ['JetBrains Mono', 'monospace']
      }
    }
  }
}

Best Practices

1

Limit font weights

Only load the font weights you actually use to reduce bundle size.
2

Use variable fonts

Variable fonts provide all weights in a single file, improving performance.
3

Preload critical fonts

Preload fonts used above the fold for faster initial rendering.
4

Provide fallbacks

Always specify fallback fonts that match your custom font’s metrics.

Performance Considerations

The @nuxt/fonts module automatically:
  • Optimizes font loading with font-display: swap
  • Generates local fallback fonts
  • Prefetches font resources
  • Provides type-safe font configuration
Avoid loading too many font weights or styles, as this increases page load time and negatively impacts performance.

Learn More

Build docs developers (and LLMs) love