PDF download Download Article
Customize your CSS projects in just a few clicks
PDF download Download Article

If you're wondering how to import Google's web fonts into your CSS code, you've come to the right place. To start using Google Fonts on your website, you'll just need to add some simple code you generate on the Google Fonts website to your existing style sheet. We'll show you how to use the @import class in CSS to display Google web fonts on your website.

Google Font Import in CSS: Quick Steps

  1. Select a font style from https://fonts.google.com.
  2. Click the circle next to @import and copy the code that appears.
  3. Open a CSS file or HTML document on your computer.
  4. Paste the code into the top line of CSS docs or between the <style></style> tags in HTML.
  5. Add text and style effects into the code as you like.
  6. Save your CSS or HTML file to finish.
  1. Go to https://fonts.google.com and click the font you want to use.[1] Scroll down the list to view all styles, and then click 'Select this style on the style you like most.[2]
  2. Under "Use on the web" on the right side of the page, select the circle next to "@import". Now you'll see some code appear in the box. Just copy the part of the code between the <style></style> tags, e.g., @import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300&display=swap');.[3]
    Advertisement
  3. If you're using a separate style sheet, open the .css file that you want to edit in your text editor. If you're doing in-line CSS, open the HTML file in which you want to use the font.
  4. If you're editing a separate CSS file, paste the copied @import information to the top of the sheet—the very first line(s).[4] If you're working in an HTML file, paste the copied code between your <style></style> tags, which should be in your header.[5]


    If you're working with an HTML file, your font information should look something like this:

    <!DOCTYPE html>
    <html>
      <head>
        <title>Title</title>
        <style>
          @import url('https://fonts.googleapis.com/css2?family=Lora&display=swap');
              </style>
      </head>
      <body>
        <h1>Lorem Ipsum</h1>
      </body>
    </html>
    

    If you're working in a separate style sheet, you'll have something like this as the first line of your CSS file:

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

  5. Now that you've added the code that makes the font available for use, you can define it in styles, such as for the body and h1 elements. For example, if you want to make your standard body text the Lora font at 20px, you could enter this into your style sheet or between your style tags:[6]
    body {
      font-family: 'Lora';
      font-size: 20px;
    }
    
    • You can change the color and text appearance of your font in the "color" and "font-weight" properties.
    • If you want to add more text effects, check out Google's list of supported text effects at https://developers.google.com/fonts/docs/getting_started. There are tons of cool effects, including fire-animation, neon, and anaglyph!
  6. Once you add the font to some CSS declarations and save your file, you're all set! Load up the page in your web browser—the browser will fetch the Google fonts and display them with the properties you specified.
    • You can include more than one Google font in your CSS code at a time. Just be aware that since the fonts are being imported into your CSS, using multiple fonts can impact loading speed. If you want to include multiple Google fonts, you'll just need to copy the code for each font you want to use and paste it into your code the same way you did here.
  7. Advertisement

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!

You Might Also Like

Upload Your Own Fonts to HTML Using CSSUpload Your Own Fonts to HTML Using CSS
Change the Font on Tumblr Change the Font on Your Tumblr Blog and Theme
Change Text Color in HTML Change Text Color in HTML and CSS
Use Font Color Tags in HTMLUse Font Color Tags in HTML
Create a Simple CSS Stylesheet Using NotepadCreate a Simple CSS Stylesheet Using Notepad
Change Your Font in Your Google Inbox Emails Change Your Font in Your Google Inbox Emails: 4 Ways
Change the Button Color in HTMLChange the Button Color in HTML
Learn Web DesignLearn Web Design
Install TrueType Fonts on Ubuntu Install TrueType (.TTF) Fonts on Ubuntu Linux: Complete Guide
Install Fonts on Your PC Install Custom Fonts on Windows or Mac Computer
Add Fonts to Photoshop3 Ways to Simply Import Fonts to Photoshop
Add Font in Microsoft Word Install and Add a Font in Microsoft Word
Add a New Font to InDesign Add Fonts in Adobe InDesign
Add Fonts to FigmaHow Figma Designers Can Access & Add New Fonts
Advertisement

About This Article

Luigi Oppido
Reviewed by:
Computer & Tech Specialist
This article was reviewed by Luigi Oppido and by wikiHow staff writer, Darlene Antonelli, MA. Luigi Oppido is the Owner and Operator of Pleasure Point Computers in Santa Cruz, California. Luigi has over 25 years of experience in general computer repair, data recovery, virus removal, and upgrades. He is also the host of the Computer Man Show! broadcasted on KSQD covering central California for over two years. This article has been viewed 46,538 times.
How helpful is this?
Co-authors: 3
Updated: December 9, 2024
Views: 46,538
Categories: Google Applications
Article SummaryX

1. Get the code for the font.
2. Open your CSS document with a text editor.
3. Paste the copied line into your code.
4. Save your CSS file.

Did this summary help you?

Thanks to all authors for creating a page that has been read 46,538 times.

Is this article up to date?

Advertisement