How to Add Google Fonts Using CSS

9,936 views · 2 min read · Tutorials

Google Fonts offers a wide range of fonts that you can easily integrate into your website. This guide will walk you through how to add Google Fonts to your site using CSS.

Step 1: Choose Your Font from Google Fonts

Visit Google Fonts and browse the available fonts. Once you find a font you like (for example, Roboto, Lobster, or Open Sans), click on it and select the styles you want to use.

Google Fonts will provide you with the necessary embed code, either an @import statement or a <link> tag. Here is an example

Step 2: Add the Font to Your Website

You can include the selected font in your site using the following method.

Using @import in custom CSS

Go to System > Modules > Custom CSS and add this at the top:

@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');

Step 3: Apply the Font in CSS

Once you’ve loaded the font, apply it to your elements using the font-family property in your CSS. Below are a few examples:

Example 1: Apply Roboto font to the entire page

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

Example 2: Use Lobster for headings only

@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap');

h1, h2, h3 {
  font-family: 'Lobster', cursive;
}

Example 3: Set Open Sans for paragraph text

@import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');

p {
  font-family: 'Open Sans', sans-serif;
}

Chaining Multiple fonts in a single import

Instead of importing fonts one by one, Google Fonts allows you to chain multiple font families inside a single @import statement.

Here’s an example:

<style>
@import url('https://fonts.googleapis.com/css2?family=Arimo:ital,wght@0,400..700;1,400..700&family=Cabin:ital,wght@0,400..700;1,400..700&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Roboto:ital,wght@0,100..900;1,100..900&display=swap');
</style>

What’s Happening Here?

Each family= parameter loads one font.

In this example, we’re importing:

  • Arimo
  • Cabin
  • Poppins
  • Roboto

Instead of four separate requests, everything is bundled into one single request.

Here is a video reference:

That’s cleaner and better for performance.

Important Best Practices

  • Always place @import at the very top of your CSS.
  • Always provide fallback fonts (like sans-serif, serif, or cursive) in case the Google Font fails to load.
  • Only load the weights you actually need (don’t load 100–900 if you’re only using 400 and 700).
  • If performance matters, consider using <link> in <head> instead of @import (it loads slightly faster).

Was this article helpful?

Thanks for the feedback.

Need further assistance?

Email support@commercebuild.com or open a ticket and we'll get back to you.

Submit a ticket