Search code examples
cssgatsbygoogle-fontsgatsby-plugin

Gatsby - Adding Google fonts to Gatsby site


I'm trying to add a Google Font (Mukta Malar) in my Gatsby site.

I've seen many articles on adding Google fonts to a Gatsby site and most of them seem to use this plugin: gatsby-plugin-prefetch-google-fonts.

I've used the above plugin in my site by adding it in the gatsby-config.js file as:

plugins: [
    {
      resolve: `gatsby-plugin-prefetch-google-fonts`,
      options: {
        fonts: [
          {
            family: `Mukta Malar`
          },
        ],
      },
    }
  ]

and added the font family to my css file as well:

* {
  font-family: "Mukta Malar", sans-serif;
}

But the Google font is not applying to the site. Is there a hidden step that I'm missing in my code?


Solution

  • This plugin seems to be no longer maintained and it's part of escalade monorepo (which throws a 404 error), last commit in the core from 1 year ago.

    I would suggest gatsby-plugin-google-fonts that allows you to display: swap your fonts without affecting your performance. In your case:

    {
      resolve: `gatsby-plugin-google-fonts`,
      options: {
        fonts: [
          `mukta malar`
        ],
        display: 'swap'
      }
    }