how to add a google font to css code example

Example 1: add google font

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

HTML
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto"/>

body{
  font-family: "Roboto";
}

Example 2: import google font css

@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');
.generic_class {
	font-family: 'Open Sans', sans-serif;
}

Example 3: how to import google font

<!-- To Add Montserrat font or any font as such -->
<!-- Go to https://fonts.google.com browse the font you like here, Montserrat-->
<!-- On the right click embbed and get the link similar to one given below-->
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
<!-- add this ^ link inside your <head> tag i.e. before </head> -->
<!-- In css you can specify the font family as -->
font-family: "Montserrat", sans-serif;

Example 4: google fonts css

Check out the font names and change 'finger paint' to another font name to how different google font appears on webpage.
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Finger Paint' rel='stylesheet'>
<style>
body {
    font-family: 'Finger Paint';font-size: 22px;
}
</style>
</head>
<body>

<h1>Finger Paint</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
<p>123456790</p>
<p>ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>
<p>abcdefghijklmnopqrstuvwxyz</p>

</body>
</html>

Example 5: use google font in html

body {
    font-family: '*Insert google font';font-size: 22px;
}

Example 6: how to setup google fonts in html and css

font-family: '<custom_font_you_selected>', <fallback_font>

Tags: