html

How to Use Google Icons in HTML & CSS?

Icons are visual representations of different actions, programs, or files and can play a very significant role in website design. They can enhance the overall look of the website and prove to be a good source of attracting more audience to your website. Icons provide easy navigation, thereby, increasing user experience. There is a vast range of icons that you can add to your website, however, this article is designed to guide you on how to use Google Icons in HTML & CSS.

Topics explored in this write-up are:

  1. What are Google Icons?
  2. How to add a Google Icon?
  3. Resizing a Google Icon
  4. Modifying the Color of a Google Icon

Let’s begin.

What are Google Icons?

Google provides a huge variety of icons (a total of 750) that are regarded as Material Design Icons. These icons are plain yet modern and represent actions or objects commonly used. For instance, a dustbin icon represents the “delete” action. These icons are supported by all present-day browsers. The screenshot attached below shows some of the material design icons.

Now that we know what google icons are, let’s learn how to add them to web pages.

How to add a Google Icon?

For the purpose of adding google material design icons to your websites follow the below-mentioned steps.

Step 1
First step is to add the link of material-icons font library in the <head> section of your HTML file. Here is how you do it.

<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>

Step 2
Once you have added the link of the material-icons library, the next step is to add the class “material-icons” in the <i> or <span> tag of the <body> section and also add the name of the icon.

<body>
<i class="material-icons">wifi</i>
</body>

Example 1
In this example, a settings icon is being added in the web page.

<html>
    <head>
        <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    </head>
    <body>
        <i class="material-icons">settings</i>
    </body>
</html>

Output

Settings icon successfully added.

Example 2
In the example below, a logout icon is being added in the web page.

<html>
    <head>
        <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    </head>
    <body>
        <i class="material-icons">logout</i>
    </body>
</html>

Output

Logout icon successfully inserted.

You can also alter the size of these material design icons using CSS. Let’s explore it in detail.

Resizing a Google Icon

You can alter the size of google material design icons according to your desire using CSS. Follow the steps mentioned in this section in order to resize your google material design icon.

Step 1
In the <style> tag using the material-icons class define the size of the icon, for example.

<style>
.material-icons.md-18 {font-size: 18px;}
</style>

Step 2
Use the same class in the <i> tag along with the icon name.

<i class= "material-icons.md-18>wifi</i>

Example
Suppose, you want to set the size of the settings icon to 48px.

<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>

.material-icons.md-48 { font-size: 48px; }

</style>
</head>
<body>

<i class="material-icons md-48">settings</i>

</body>
</html>

Output

Size of the settings icon successfully changed.

Besides size, you can also modify the color of the google icons. Let’s see how it is done.

Modifying the Color a Google Icon

For the purpose of changing the color of google material design icons follow the same steps as mentioned in the above section with a slight difference that along with the font-size you can have to define the color using the color property of CSS.

<style>
.material-icons.md-36 { font-size: 36px; color: red; }
</style>

Example
Suppose, you want to change the color of settings icon to blue.

<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>

.material-icons.md-48 { font-size: 48px; color: blue; }

</style>
</head>
<body>

<i class="material-icons md-48">settings</i>

</body>
</html>

Output

The color of the settings icon successfully changed.

Conclusion

To embed Google Icons in your HTML web pages you have to add the link of material-icons font library in the <head> section of your HTML file and then add the class material-icons in the <i> or <span> tag of the <body> section along with the name of the icon. You can also alter the size and color of the icons through CSS by defining them in the <style> tag using the material-icons class. This write-up discusses how to use google icons in HTML & CSS in depth with the help of appropriate examples.

About the author

Naima Aftab

I am a software engineering professional with a profound interest in writing. I am pursuing technical writing as my full-time career and sharing my knowledge through my words.