PHPackages                             nguyenhiep/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. nguyenhiep/laravel-google-fonts

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

nguyenhiep/laravel-google-fonts
===============================

Manage self-hosted Google Fonts in Laravel apps

v1.1(4y ago)064MITPHPPHP ^7.4|^8.0

Since Jun 22Pushed 4y agoCompare

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

READMEChangelog (1)Dependencies (9)Versions (4)Used By (0)

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)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3117f7404da49e37125273f508204695f48bd0241712e672c7252162628e93e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d676f6f676c652d666f6e74732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/spatie/laravel-google-fonts/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/914b1bd166ed0c020898d51e8385126e5cb84c29a740cd71c1b6c74e2b8393fe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d676f6f676c652d666f6e74732f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/spatie/laravel-google-fonts/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![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 nguyenhiep/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 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
```

### 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](.github/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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.4% of commits — single point of failure

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 ~1 days

Total

3

Last Release

1785d ago

Major Versions

0.0.1 → 1.0.02021-06-23

PHP version history (2 changes)0.0.1PHP ^8.0

v1.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ee7ece29e66e7029d6b12d947a7d9714ae36346f21e92d767cfc797b86949d8?d=identicon)[nguyenhiepvan](/maintainers/nguyenhiepvan)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (26 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (13 commits)")[![nguyenhiepvan](https://avatars.githubusercontent.com/u/33170716?v=4)](https://github.com/nguyenhiepvan "nguyenhiepvan (2 commits)")

---

Tags

spatielaravelgoogle fontslaravel-google-fonts

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-google-fonts

Manage self-hosted Google Fonts in Laravel apps

4891.0M12](/packages/spatie-laravel-google-fonts)[spatie/laravel-data

Create unified resources and data transfer objects

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

Monitor the health of a Laravel application

85810.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)

PHPackages © 2026

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