Contents  >

Introduction to Google Fonts

Learning Goals

At the end of this Tutorial you will be able to:

You can view finished versions of the four sample web pages you will update with Google Fonts in this Tutorial by clicking the links below. The finished samples will each open in a new tab of your web browser.

You created these four sample web pages and their linked stylesheets in the previous Introduction to Images Tutorial.

Sample image page-5.html
Sample image page-6.html
Sample image page-7.html
Sample image page-8.html

Contents

About Google Fonts

Google Fonts: the two steps

One: Making the Google Font available to your web page

Two: Updating the <font-family> in your CSS file

Popular fonts in 2020

Working with the van Gogh sample web page

Working with the Tourism sample web page

Working with the Smoothies sample web page

Working with the Software sample web page

Uploading your files to GitHub

Further resources

About Google Fonts

Google Fonts offers the Internet’s largest collection of open-source, royalty-free fonts. All 900-plus fonts can be used without restriction for personal, not-for-profit or commercial web projects.

Below is a screenshot of the Google Fonts home page at:

https://fonts.google.com

Introduction to Google Fonts

To preview a particular font, click on it. To see how a few words of text will look when styled in the selected font, type your chosen text in the Type here to preview text box.

Introduction to Google Fonts

Google Fonts: the two steps

There are two basic steps to using Google Fonts. They are as follows.

One: Making the Google Font available to your web page

In this first step, you add a line similar to the following to the <head> of your HTML file.

Introduction to Google Fonts

In this example, the name of the Google Font is ‘Roboto’.

For every Google font, the text within the href="" attribute follows the same format. Only the name of the font is different.

Here are some more examples, showing only the href="" part for readability.

Introduction to Google Fonts

If the Google Font you want to use has more than one word in its name, you need to add a plus sign (+) between the words. See the examples below for the fonts named ‘Open Sans’ and ‘Source Sans Pro’.

Introduction to Google Fonts

Two: Updating the <font-family> in your CSS file

Your second step to using a Google Font is to add the font name to the font-family property of the relevant heading or paragraph text selector within your stylesheet.

For example, to use the ‘Kinsta’ font for your <h1> headings, you would edit the h1 selector in your CSS file as follows.

Introduction to Google Fonts

To use the ‘PT Sans’ font for your <h3> headings, you would edit the h3 selector in your CSS file as follows.

Introduction to Google Fonts

And if you wanted to use the ‘Work Sans’ font for your text paragraphs, you would edit the p selector in your CSS file as follows.

Introduction to Google Fonts

Note that the font name is always wrapped in a pair of single quotation marks (‘ ’).

You can also see that every Google Font name is followed by a comma (,) and what is called a fallback font – either serif or sans-serif. This is the font that is displayed when the web page is viewed without a live Internet connection.

As with much else, there are fashions and trends in fonts. Here are the more widely-used serif and sans-serif fonts at the moment.

Introduction to Google Fonts

Working with the van Gogh sample web page

In this section, you will work with the sample page-5.html web page and the sample style-5.css stylesheet.

  1. In Visual Studio Code, open the following two files:   page-5.html
    style-5.css
  2. In the <head> of the web page, copy-and-paste the following lines just before the closing </head> tag.
    <!-- Google Font -->
    <link href="https://fonts.googleapis.com/css2?family=Merriweather&display=swap" rel="stylesheet">  
    
  3. In your stylesheet, update the font of the heading and paragraph styles as follows: Introduction to Google Fonts
  4. When finished, save your page-5.html and style-5.css files, and view the web page in your browser.

Click page-5.html to view a finished sample of this web page in a new tab of your web browser.

Working with the Tourism sample web page

In this section, you will work with the sample page-6.html web page and the sample style-6.css stylesheet.

  1. In Visual Studio Code, open the following two files:   page-6.html
    style-6.css
  2. In the <head> of the web page, copy-and-paste the following lines just before the closing </head> tag.
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Oswald&display=swap" rel="stylesheet">  
    <link href="https://fonts.googleapis.com/css2?family=Lato&display=swap" rel="stylesheet">  
    
  3. In your stylesheet, update the font of all the heading styles as follows: Introduction to Google Fonts
  4. And update the font of the paragraph styles as follows: Introduction to Google Fonts
  5. When finished, save your page-6.html and style-6.css files, and view the web page in your browser.

Click page-6.html to view a finished sample of this web page in a new tab of your web browser.

Working with the Smoothies sample web page

In this section, you will work with the sample page-7.html web page and the sample style-7.css stylesheet.

  1. In Visual Studio Code, open the following two files:   page-7.html
    style-7.css
  2. In the <head> of the web page, copy-and-paste the following lines just before the closing </head> tag.
    <!-- Google Font -->
    <link href="https://fonts.googleapis.com/css?family=Neucha&display=swap" rel="stylesheet">  
    
  3. In your stylesheet, update the font of the heading and paragraph styles as follows: Introduction to Google Fonts
  4. When finished, save your page-7.html and style-7.css files, and view the web page in your browser.

Click page-7.html to view a finished sample of this web page in a new tab of your web browser.

Working with the Software sample web page

In this section, you will work with the sample page-8.html web page and the sample style-8.css stylesheet.

  1. In Visual Studio Code, open the following two files:   page-8.html
    style-8.css
  2. In the <head> of the web page, copy-and-paste the following lines just before the closing </head> tag.
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Domine&display=swap" rel="stylesheet">  
    <link href="https://fonts.googleapis.com/css2?family=PT+Sans&display=swap" rel="stylesheet">  
    
  3. In your stylesheet, update the font of the heading and paragraph styles as follows: Introduction to Google Fonts
  4. When finished, save your page-8.html and style-8.css files, and view the web page in your browser.

Click page-8.html to view a finished sample of this web page in a new tab of your web browser.

Uploading your files to GitHub

After finishing your web pages and stylesheets, you are now ready to upload them to your account on GitHub.

  1. Open a new tab in your web browser and go to GitHub.com. If you are not already signed in to your GitHub account, sign in now. github-signin
  2. On your GitHub home page, click the name of the repository (‘repo’) that holds your web pages. Its name will look as follows, where username is your chosen username on GitHub.   username.github.io github-signin
  3. On the next GitHub screen displayed, click the websites folder. This is where you sample web pages, stylesheets and images are contained. github-signin
  4. On the next GitHub screen, click the Add file button. github-upload-portfolio
  5. From the dropdown list displayed, choose the option Upload files. Introduction to Google Fonts
  6. Select or drag-and-drop the following web pages and stylesheets to upload them to the websites folder of your GitHub account::   page-5.html
    page-6.html
    page-7.html
    page-8.html
    style-5.css
    style-6.css
    style-7.css
    style-8.css
  7. Finally, scroll down to the bottom of the GitHub screen, accept or edit the short message (Add files via upload) in the Commit changes box and click the Commit changes button.

Your web pages and stylesheets are now published on GitHub at web addresses similar to the following, where username is the username you have chosen for your GitHub account:

https://username.github.io/websites/page-5.html
https://username.github.io/websites/page-6.html
https://username.github.io/websites/page-7.html
https://username.github.io/websites/page-8.html

It may take a few minutes for your uploaded files to appear on GitHub.

Further resources

How to: Google Fonts
from W3 Schools

Get Started with the Google Fonts API
from Official Google Developer Blog

93 most popular premium fonts: free Google Font alternatives
from Design Way

25 Most Popular Google Fonts - 2020
from UX Planet

The Ultimate Collection of Google Font Pairings
from Reliable PSD

Top 10 Beautiful Google Font Combinations in 2020
from Linkbot Design

The Top 50 Google Font Pairings
from Page Cloud



Return to Contents.