Practice Using Google Fonts

Activity

Objective: Use a Google font.

Setup:

Copy all the files from the start-01 folder to practice folder and replace if necessary.

The activity's completed file can be found in the completed folder.

Steps:

  1. Open your web browser and navigate to Google Fonts.

    Google Fonts site all fonts

    Google Fonts changes its web site design from time to time. Your view may be different.

    Google Fonts provides a catalog of available fonts and a dialog panel that allows you to search or filter fonts.

  2. In the search filter panel Categories pane uncheck all but Sans Serif.

    Google Fonts site category Sans Serif selected

    A number of sans serif fonts will apppear. A popular san serif font is called Roboto. If it does not appear. You can type the name in the Search box to further filter the listing.

  3. Hover over the Roboto name area and a series of selection drop downs are presented. Select the one showing the font styles.

    Google Fonts Roboto 400 selected

    You will see that Regular 400 is pre-selected. Then close the styles drop down.

  4. Select the plus icon in top right corner opposite the Roboto font name. This adds it to a cart panel.

    Google Fonts Roboto 400 selected

    The plus changes to a minus and a cart panel appears at the bottom of the page.

  5. Next select the plus icon in top right corner opposite the Roboto font name.

    Google Fonts open cart panel

    This contains all fonts you may have selected.

    Google Fonts open cart panel

  6. Keep the web browser tab for Google fonts open. Open the roboto.html file in a second tab in your web browser.

    Practice file in browser at activity start.

  7. Open the roboto.css file in your code editor. It has the following contents:

    @charset "UTF-8";
    
    body{
    	font-family:Arial, Helvetica, sans-serif;
    }

    Does the body selector use web safe fonts or web fonts?

    These are common web safe fonts.

    What font family was selected for the body selector and how could you find out?

    It was one of the three font-family values: Arial, Helvetica and sans-serif.

    The web browser tools can be used to discover the font family selected. Here is the result on a Macintosh using Chrome.

    Practice file in web Chrome inspecting body element.

  8. In the roboto.css file replace the following …

    Arial, Helvetica, sans-serif;

    … with the following …

    'Roboto', sans-serif;

    … resulting in …

    body{
    	font-family:'Roboto', sans-serif;
    }

    … and save.

  9. Reload the roboto.html file in your web browser.

    What changed? Explain your answer.

    The operating system provided a sans-serif font unless by chance the Roboto font was installed in the operating system by the owner, you.

    Here Helvtica is shown using Chrome tools on a Macintosh.

    Practice file in web Chrome inspecting body element after using Roboto font family.

    Why was the Roboto font not selected?

    It is not available on the system. It needs to be downloaded.

  10. In the roboto.html file insert before …

    	<link rel="stylesheet" type="text/css" href="roboto.css">

    … the following …

    	<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

    … and save.

  11. Reload the roboto.html file in your web browser.

    Practice file in browser after adding Roboto 400 stylesheet

    Why are the h1 and h3 elements no longer boldfaced?

    We are applying the Roboto font using the 400 medium style to all the elements. That represents a regular font weight. It is the same as applying font-weight:normal to the body selector for fonts that support a boldface style.

  12. In the roboto.css file insert at end of the file …

    h1, h3{
    	font-weight:bold;
    }

    … and save.

  13. Reload the roboto.html file in your web browser.

    Explain why bold was not applied to h1 and h3?

    No change in font styling.

    Practice file in browser after adding bold to h1 and h3 elements.

    Explain why bold was not applied to h1 and h3?

    The answer is that the Roboto font using the 400 medium style does not support font weight for bold.

    What numeric value for the font-weight represents bold and would using it for the h1 and h3 selectors change them to bold?

    The numeric value of 700 is the equivalent of the value bold. However using that would not change the fact that the Roboto font using the 400 medium style does not support bold.

  14. Return to the Google Fonts tab you kept open in your web browser and close the font selection panel.

    Google Fonts open cart panel close button

  15. Add the Roboto Bold 700 style to the font selection and open the font selection panel.

    Steps for adding Roboto Bold 700 at Google Fonts site.

    Google Fonts open cart panel showing Roboto 400 and 700 styles selected.

    What changes do you notice from the previous selection of the Roboto Medium 400?

    The link element has changed. The link element as it appeared with Roboto Medium 400 …

    	<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
    

    The link element as it appeared with Roboto Medium 400 and Roboto Bold 700 …

    	<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
  16. In the roboto.html file replace …

    	<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

    … with the following …

    	<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">

    … and save.

  17. Reload the roboto.html file in your web browser.

    Practice file in web browser showing the Roboto Bold 700 font style for the h1 and h3 elements.

  18. Verify using web browser tools that the Roboto Bold 700 style was applied to the h1 and h3 elements.

    You can use your web browser inspection tools. For the h1 element …

    Chrome inspect h1 element showing Roboto font family and the font weight of 700.

    For the h3 element …

    Chrome inspect h3 element showing Roboto font family and the font weight of 700.

  19. DIY: Add the Roboto Black 900 font style and apply to the h1 element and keep the Roboto Bold 700 applied to the h3 element.

    Page in web browser …

    Practice file in web browser using Roboto Black 900 for the h1 element.

    … and inspecting the h1 element …

    Chrome inspect h1 element using the Roboto Black 900 font.

    The change to the roboto.html file …

    	<link href="https://fonts.googleapis.com/css?family=Roboto:400,700,900" rel="stylesheet">

    Change shown in bold.

    The change to the roboto.css file …

    h1{
    	font-weight:900;
    }
    h3{
    	font-weight:700;
    }

    Did you need to have Google fonts generate the link element?

    No. The element only needed to be changed by adding the 900 to the href attribute URL. Applying to the h3 element used a standard numeric value for the font-weight property.

  20. DIY: Provide fallback web safe fonts for the Roboto font.

    body{
    	font-family:'Roboto', Arial, Helvetica, sans-serif;
    }

    Change shown in bold.

Complete and Continue