Skip to main content
The next/font module provides automatic font optimization with zero layout shift, reduced network requests, and built-in subsetting.

Google Fonts

Import fonts from Google Fonts CDN (dev) or self-host them (production).

Import

Basic Usage

API Reference

string[]
required
Font subsets to load (reduces file size).Common subsets:
  • 'latin' — Latin alphabet (English, French, German, etc.)
  • 'latin-ext' — Extended Latin (Eastern European)
  • 'cyrillic' — Cyrillic alphabet (Russian, Ukrainian, etc.)
  • 'greek' — Greek alphabet
  • 'vietnamese' — Vietnamese
string | string[]
Font weights to load.
string | string[]
default:"'normal'"
Font styles to load.
string
default:"'swap'"
CSS font-display value.
  • 'swap' — Show fallback immediately, swap when loaded (recommended)
  • 'optional' — Use font if cached, otherwise use fallback
  • 'fallback' — Brief block period, then swap
  • 'block' — Block rendering until font loads (avoid)
boolean
default:"true"
Add <link rel="preload"> for faster loading.
string[]
default:"['sans-serif']"
Fallback fonts when the web font is loading or unavailable.
boolean
default:"true"
Automatically adjust fallback fonts to reduce layout shift.
string
CSS variable name for the font.

Return Value

string
CSS class name that applies the font.
{ fontFamily: string }
Inline style object with fontFamily.
string
CSS class name that sets the CSS variable.

Examples

Multiple Fonts

With Tailwind CSS

Single Page

Local Fonts

Use fonts from local files.

Import

Basic Usage

API Reference

string | LocalFontSrc | LocalFontSrc[]
required
Font file path(s).Single file:
Multiple weights:
string
Default font weight (when using single src string).
string
default:"'normal'"
Default font style.
string
default:"'swap'"
CSS font-display value (same as Google Fonts).
string[]
Fallback fonts.
string
CSS variable name.
boolean
default:"true"
Add preload hint.
Array<{ prop: string; value: string }>
Custom CSS properties for the @font-face rule.

Examples

Variable Font

Multiple Weights and Styles

Self-Hosting Google Fonts

In production builds, vinext automatically downloads and self-hosts Google Fonts:
  1. Build time: Plugin fetches font CSS and .woff2 files from Google
  2. Assets: Fonts are bundled with your app
  3. Runtime: No requests to Google Fonts CDN
Benefits:
  • Faster loading (no DNS lookup, no third-party request)
  • Better privacy (no data sent to Google)
  • Works offline
Dev mode: Fonts load from Google CDN (faster iteration).

Performance

Zero Layout Shift

vine automatically generates fallback font metrics to prevent layout shift:

Subsetting

Loading only the characters you need:

Preloading

Preload hints ensure fonts load early:

CSS Variables

Use CSS variables for flexible theming:

Common Fonts

vinext provides named exports for popular Google Fonts:
For other fonts, use the dynamic accessor:

Limitations

Module-level only: Font loaders must be called at module level (not inside components).
Local font paths: Must be relative to the file where localFont is called.
Build-time download: Google Fonts are fetched at build time. Network issues during build will cause failures.

Source

View Google Fonts source → View local fonts source → Implementation:
  • /home/daytona/workspace/source/packages/vinext/src/shims/font-google.ts
  • /home/daytona/workspace/source/packages/vinext/src/shims/font-local.ts