Open In App

How to Import Google Fonts in HTML?

Last Updated : 23 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Choosing the right font for your webpage is a very important aspect of any design. Using a web font service enables you to use a wide variety of fonts fit for presenting the data on your webpage. Google Fonts is a free web font service that hosts a huge variety of fonts to choose from. We can use these fonts in our webpages. To use a custom font, we need to import the font family from the web font service, Google Fonts, in this case.

Below are the approaches to import the Google Font into the HTML document:

In this approach, we are using the link tag to add the google font link into out HTML document. It will allow us to use that specific font into out HTML document.

Syntax:

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

Example: This example shows the use of link tag for import of google font.

html
<!DOCTYPE html>
<html>

<head>
    <link href=
'https://fonts.googleapis.com/css?family=Sofia'
        rel='stylesheet' />
    <style>
        h1 {
            font-family: Sofia;
            color: green;
        }
    </style>
</head>

<body>
    <center>
        <h1>GeeksforGeeks</h1>
    </center>
</body>

</html>

Output:

Using @import rule

In this approach, we are using the @import url to import the google font. that will help us to access that specific google font into our HTML document.

Syntax

  @import url('https://fonts.googleapis.com/css?family=Poppins'); 

Example: This example shows the use of @import for import of google font.

html
<!DOCTYPE html>
<html>

<head>
    <style>
        @import url(https://fonts.googleapis.com/css?family=Open+Sans);

        h1 {
            font-family: 'Open Sans', serif;
            color: green;
        }
    </style>
</head>

<body>
    <center>
        <h1>
            GeeksforGeeks
        </h1>
    </center>
</body>

</html>

Output:


Next Article

Similar Reads