- Twig Function - Simple
{{ google_fonts() }}function - Development Mode - Google Fonts CDN with inline styles
- Production Mode - Lock fonts locally for better performance and privacy
- Smart CSS - Automatic font styling for body, headings, and bold text
- CLI Tools - Search, import, lock, and warm-cache commands
- High Performance - Optimized with full template caching support
For fully automatic setup, visit the related Flex recipe repository and follow the instructions to add it to the composer.json in the consuming project, as the recipe is not yet part of the Symfony’s main recipe repository.
composer require neuralglitch/google-fonts{# templates/base.html.twig #}
<head>
{# Normal font for body and headings #}
{{ google_fonts('Ubuntu', '300 400 500 700', 'normal italic') }}
{# Monospace font for code elements #}
{{ google_fonts('JetBrains Mono', '400 500', 'normal', null, true) }}
</head>php bin/console gfonts:lockThis downloads fonts to assets/fonts/ (served by AssetMapper in dev, compiled to public/ in prod).
Each font gets a single CSS file containing both @font-face declarations and intelligent styling rules.
The bundle automatically switches to locked fonts in production (via when@prod configuration).
Troubleshooting: If locked fonts aren't being used in production, see DEBUG_LOCKED_FONTS.md.
# .env.local
GOOGLE_FONTS_API_KEY=your_api_key_hereGet your free API key at Google Cloud Console.
Note: The API key is only required for gfonts:search and gfonts:import commands. The google_fonts() Twig function and gfonts:lock command do NOT require an API key.
- Usage Guide - Detailed examples and function parameters
- Commands - CLI command reference
- Configuration - Configuration options
- Production Setup - Deploying with locked fonts
- Development - Contributing and testing
- PHP 8.1 or higher
- Symfony 6.4, 7.x, or 8.x
- Twig 3.0 or higher