PHPackages                             spatie/laravel-google-fonts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/laravel-google-fonts

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/laravel-google-fonts
===========================

Manage self-hosted Google Fonts in Laravel apps

1.5.0(2mo ago)4891.0M—5.7%3611MITHTMLPHP ^8.0CI passing

Since Jun 22Pushed 2mo ago8 watchersCompare

[ Source](https://github.com/spatie/laravel-google-fonts)[ Packagist](https://packagist.org/packages/spatie/laravel-google-fonts)[ Docs](https://github.com/spatie/laravel-google-fonts)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-google-fonts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (17)Used By (11)

Manage self-hosted Google Fonts in Laravel apps
===============================================

[](#manage-self-hosted-google-fonts-in-laravel-apps)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ad7b84a70e1d89090767f2342adfd13689dbe5e8f52e43ef13ce1c16de8206cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d676f6f676c652d666f6e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-google-fonts)[![run-tests](https://github.com/spatie/laravel-google-fonts/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-google-fonts/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/3093bbd16e1888395524d82aba8546d034773feff0feb4c834fdfedc85005b8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d676f6f676c652d666f6e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-google-fonts)

This package makes self-hosting Google Fonts as frictionless as possible for Laravel users. To load fonts in your application, register a Google Fonts embed URL and load it with the `@googlefonts` Blade directive.

```
// config/google-fonts.php

return [
    'fonts' => [
        'default' => 'https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,700;1,400;1,700&display=swap',
        'code' => 'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,700;1,400&display=swap',
    ],
];
```

```
{{-- resources/views/layouts/app.blade.php --}}

    {{-- Loads Inter --}}
    @googlefonts

    {{-- Loads IBM Plex Mono --}}
    @googlefonts('code')

```

When fonts are requested the first time, this package will scrape the CSS, fetch the assets from Google's servers, store them locally, and render the CSS inline.

If anything goes wrong in this process, the package falls back to a `` tag to load the fonts from Google.

Why we created this package
---------------------------

[](#why-we-created-this-package)

Google Fonts hosts an impressive catalog of fonts, but relying on it has its costs. By hosting fonts on an external domain, browsers need to perform an additional DNS lookup. This slows down the initial page load. In addition, you're directing your visitors to Google property, which privacy-minded users might not appreciate.

You can download fonts from Google Fonts and self-host them, but it's more work than embedding a code. Keeping up with the latest font version can also be a chore.

This package makes self-hosting Google Fonts as frictionless as possible for Laravel users.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/468536e650f286afa805167d066ac7f5db407fbc1abb3a4993ac5a356945d1cf/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d676f6f676c652d666f6e74732e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-google-fonts)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-google-fonts
```

You may optionally publish the config file:

```
php artisan vendor:publish --provider="Spatie\GoogleFonts\GoogleFontsServiceProvider" --tag="google-fonts-config"
```

Here's what the config file looks like:

```
return [

    /*
     * Here you can register fonts to call from the @googlefonts Blade directive.
     * The google-fonts:fetch command will prefetch these fonts.
     */
    'fonts' => [
        'default' => 'https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,700;1,400;1,700',
    ],

    /*
     * This disk will be used to store local Google Fonts. The public disk
     * is the default because it can be served over HTTP with storage:link.
     */
    'disk' => 'public',

    /*
     * Prepend all files that are written to the selected disk with this path.
     * This allows separating the fonts from other data in the public disk.
     */
    'path' => 'fonts',

    /*
     * By default, CSS will be inlined to reduce the amount of round trips
     * browsers need to make in order to load the requested font files.
     */
    'inline' => true,

    /*
     * When preload is set to true, preload meta tags will be generated
     * in the HTML output to instruct the browser to start fetching the
     * font files as early as possible, even before the CSS is fully parsed.
     */
    'preload' => false,

    /*
     * When something goes wrong fonts are loaded directly from Google.
     * With fallback disabled, this package will throw an exception.
     */
    'fallback' => ! env('APP_DEBUG'),

    /*
     * This user agent will be used to request the stylesheet from Google Fonts.
     * This is the Safari 14 user agent that only targets modern browsers. If
     * you want to target older browsers, use different user agent string.
     */
    'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15',

];
```

Usage
-----

[](#usage)

To add fonts to your application, grab an embed code from Google fonts, register it in the config and use the `@googlefonts` Blade directive.

```
// config/google-fonts.php

return [
    'fonts' => [
        'default' => 'https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,700;1,400;1,700&display=swap',
        'code' => 'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,700;1,400&display=swap',
    ],
];
```

```
{{-- resources/views/layouts/app.blade.php --}}

    {{-- Loads Inter --}}
    @googlefonts

    {{-- Loads IBM Plex Mono --}}
    @googlefonts('code')

```

This will inline the CSS, so the browser needs to do one less round-trip. If you prefer an external CSS file, you may disable the `inline` option in the package configuration.

Fonts are stored in a `fonts` folder on the `public` disk. You'll need to run `php artisan storage:link` to ensure the files can be served over HTTP. If you wish to store fonts in the git repository, make sure `storage/app/public` is not ignored.

If you want to serve fonts from a CDN, you may set up a different disk configuration.

Prefetching fonts
-----------------

[](#prefetching-fonts)

If you want to make sure fonts are ready to go before anyone visits your site, you can prefetch them with this artisan command.

```
php artisan google-fonts:fetch
```

Usage with spatie/laravel-csp
-----------------------------

[](#usage-with-spatielaravel-csp)

If you're using [spatie/laravel-csp](https://github.com/spatie/laravel-csp) to manage your Content Security Policy, you can pass an array to the blade directive and add the `nonce` option.

```
{{-- resources/views/layouts/app.blade.php --}}

    {{-- Loads Inter --}}
    @googlefonts(['nonce' => csp_nonce()])

    {{-- Loads IBM Plex Mono --}}
    @googlefonts(['font' => 'code', 'nonce' => csp_nonce()])

```

### Caveats for legacy browsers

[](#caveats-for-legacy-browsers)

Google Fonts' servers sniff the visitor's user agent header to determine which font format to serve. This means fonts work in all modern and legacy browsers.

This package isn't able to tailor to different user agents. With the default configuration, only browsers that can handle WOFF 2.0 font files are supported. At the time of writing, this is &gt;95% of all users according to [caniuse](https://caniuse.com/woff2). Most notably, IE doesn't support WOFF 2.0.

If you need to serve fonts to a legacy browser, you may specify a different user agent string in the configuration. Keep in mind that makes the page load heavier for all visitors, including modern browsers.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community35

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~121 days

Recently: every ~177 days

Total

15

Last Release

85d ago

Major Versions

0.0.1 → 1.0.02021-06-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (55 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (21 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (8 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (5 commits)")[![alexmanase](https://avatars.githubusercontent.com/u/10696975?v=4)](https://github.com/alexmanase "alexmanase (5 commits)")[![hasan-ahani](https://avatars.githubusercontent.com/u/67734902?v=4)](https://github.com/hasan-ahani "hasan-ahani (5 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (4 commits)")[![rubanooo](https://avatars.githubusercontent.com/u/14110726?v=4)](https://github.com/rubanooo "rubanooo (3 commits)")[![zepfietje](https://avatars.githubusercontent.com/u/44533235?v=4)](https://github.com/zepfietje "zepfietje (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![fjahn](https://avatars.githubusercontent.com/u/74260729?v=4)](https://github.com/fjahn "fjahn (2 commits)")[![MrMage](https://avatars.githubusercontent.com/u/117466?v=4)](https://github.com/MrMage "MrMage (1 commits)")[![Gamzky](https://avatars.githubusercontent.com/u/30494798?v=4)](https://github.com/Gamzky "Gamzky (1 commits)")[![JayBizzle](https://avatars.githubusercontent.com/u/340752?v=4)](https://github.com/JayBizzle "JayBizzle (1 commits)")[![eugenefvdm](https://avatars.githubusercontent.com/u/1836436?v=4)](https://github.com/eugenefvdm "eugenefvdm (1 commits)")[![freshleafmedia](https://avatars.githubusercontent.com/u/10062339?v=4)](https://github.com/freshleafmedia "freshleafmedia (1 commits)")

---

Tags

spatielaravelgoogle fontslaravel-google-fonts

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-laravel-google-fonts/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-google-fonts/health.svg)](https://phpackages.com/packages/spatie-laravel-google-fonts)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[spatie/laravel-rdap

Perform RDAP queries in a Laravel app

72108.3k2](/packages/spatie-laravel-rdap)[spatie/laravel-support-bubble

A non-intrusive support chat bubble that can be displayed on any page

391173.6k](/packages/spatie-laravel-support-bubble)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
