Skip to main content

getPairingGoogleFontsUrl

Returns the Google Fonts URL for a specific font pairing by name.

Function Signature

lib/pairings.ts

Parameters

name
string
required
The name of the pairing (e.g., “editorial”, “minimal”, “brutalist”)

Returns

url
string | null
The Google Fonts URL for the pairing, or null if the pairing is not found or has no URL configured

Description

The getPairingGoogleFontsUrl() function retrieves the Google Fonts URL for a specific pairing. This URL includes all three fonts (heading, body, mono) with their required weights, optimized for loading in a single request.

Usage Examples

Basic Usage

Load Fonts Dynamically

Preload Pairing Fonts

Next.js Font Loading

Error Handling

Generate Font Preconnect Tags

URL Format

The returned URL follows the Google Fonts API v2 format:
Example for the “Editorial” pairing:
This URL includes:
  • Heading font: Playfair Display (weights: 600, 700)
  • Body font: Source Serif 4 (weights: 400, 600)
  • Mono font: JetBrains Mono (weights: 400, 500)
  • Display strategy: swap (shows fallback text immediately)

Return Value

url
string | null
  • Returns the full Google Fonts URL as a string if the pairing exists
  • Returns null if:
    • The pairing name is not found in the registry
    • The pairing exists but has no googleFontsUrl field (rare)
Always check for null before using the returned URL to avoid runtime errors.

getPairing

Get full pairing data including fonts and scale

getAllGoogleFontsUrls

Get all Google Fonts URLs across pairings

Notes

  • The function internally calls getPairing() to fetch the pairing data
  • Pairing names are case-sensitive (use lowercase names like “editorial”, not “Editorial”)
  • All current pairings include a Google Fonts URL, but the function returns null for safety
  • URLs include display=swap for optimal loading performance
  • Performance: O(n) where n is the number of pairings (linear search)

Common Pairings

  • editorial - Playfair Display + Source Serif 4 + JetBrains Mono
  • literary - EB Garamond + Crimson Text + Inconsolata
  • newspaper - Playfair Display + DM Sans + JetBrains Mono
  • minimal - Inter + Inter + JetBrains Mono
  • modern-clean - Space Grotesk + Space Grotesk + Space Mono
  • swiss - Work Sans + Work Sans + Source Code Pro
  • brutalist - Space Grotesk + Space Grotesk + Space Mono
  • impact - Bebas Neue + Barlow + Fira Code
  • poster - Alfa Slab One + Assistant + Roboto Mono

Source Reference

Implementation: lib/pairings.ts:63-66