Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add google fonts to a gatsby site

Getting started with Gatsby - when I add a link tag to public/index.html with the google font it works in development mode. When I build the site the index.html gets reset. So I guess there is another proper way to add the font?

like image 457
enginedave Avatar asked Nov 25 '17 16:11

enginedave


People also ask

Can I add to Google fonts?

It's possible to add a font to Google Docs in two simple ways. You can select "More fonts" from the main font list, and add a font to that primary tab within Google Docs. You can also download the Extensis Fonts add-on to add hundreds of additional fonts to Google Docs.

Where do I add Google fonts in WordPress?

Log into your WordPress admin panel and navigate to Plugins > Add New. Search for Easy Google Fonts and install it on your website. Once the plugin is installed, click the Activate button to begin using it.


2 Answers

You can also use react-helmet, which is discussed in the gatsby tutorial.

Include a google fonts link element within the helmet component.

Like this:

<Helmet>   <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"/> </Helmet> 

I ended up going down this route because I had already done some styling manually, and when I tried using Typography it made a bunch of changes that would have taken me a while to undo.

like image 101
martis Avatar answered Oct 13 '22 19:10

martis


Add the following to the top of src/layouts/index.css for example to import the 'Roboto' font by Google

@import url('https://fonts.googleapis.com/css?family=Roboto');  html {   font-family: 'Roboto', sans-serif; } 

This will then be handled by the gatsby build process and included in the final production version of the site.

like image 27
enginedave Avatar answered Oct 13 '22 21:10

enginedave