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 
     : 
     20 
     px 
     ; 
     } 
    
    • 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
      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!

      About This Article

      Article Summary X

      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 42,143 times.

      Is this article up to date?

      Advertisement