How to use Google Fonts


Surely you want a cool Google Font on your website?

3 May, 2020 ยท 3 min read

Google fonts are a fantastic way of adding a cool font to your website, I know Iโ€™m not using them, but that is for other purposes. I use them on client websites all the time, and they are amazing and simple to use.

Letโ€™s get started on implementing a custom font for your website.

Finding your Google Font

To find a cool font, we can go to the Google Font library and pick one we like.

Once you have found the one you want, open it up you will see the whole setโ€™s letters and Styles. Google Fonts will allow you to include more styles on your website. In my case, Iโ€™m using Amatic SC Bold. Click the Select this style button for each style you want. You will see a side menu on the right. It will have a Review and Embed section; in the embed, we can get the code.

Embedding the Google Font in your website

There are two ways of embedding the font into your website.

  • <link> attribute; this sets a link like any external stylesheet
  • @import imports it directly in the CSS

The Google Fonts website will also show you which font-family rule you must apply to each element you want to have this specific font.

This question keeps floating around on the internet, and Steve Souders did an excellent job of comparing the two. As his article title suggests, <link> is the best way to go, according to him and Yahoo.

Using the Google Font on our website


We embed the Google Font in the head of our HTML file using the following code. This is the code you get from Google Fonts.

Then in our CSS we can do the following:

h1 {
  font-family: 'Amatic SC', cursive;

Itโ€™s essential to use the name as stated on Google Fonts website.

We then have the following result:

See the Pen KKdXJQK by Chris Bongers (@rebelchris) on CodePen.

What to think about

So important to note when using Google Fonts they tend to load slowly. The more you use them, the more load time it will add. And Google itself will not like that very much. My suggestion is that you keep it to one custom font. We can use font-display: swap to not interfere with the load. More on this in another article!

Thank you for reading, and letโ€™s connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Spread the knowledge with fellow developers on Twitter
Tweet this tip
Powered by Webmentions - Learn more

Read next ๐Ÿ“–

How I made a no-div playground in Vanilla JavaScript

28 Dec, 2020 ยท 9 min read

How I made a no-div playground in Vanilla JavaScript

I made my website 28ms faster with content-visibility ๐Ÿค“

24 Sep, 2020 ยท 2 min read

I made my website 28ms faster with content-visibility ๐Ÿค“

Join 2099 devs and subscribe to my newsletter