CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Misc

What is Bootstrap CSS What is CSS used for Difference between HTML and CSS How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language Grid Vs Flexbox in CSS How to edit CSS in WordPress How to use google fonts in CSS Create a 3D text effect using HTML and CSS How to create blinking text using CSS Hover condition for a:before and a:after in CSS Difference between CSS Grid and CSS Flexbox

How to use google fonts in CSS

Fonts: -

Fonts are used to make our website look more beautiful. Choosing appropriate font according to the web design or layout is also important. Many typefaces are accessible in HTML and CSS; however, if we don't like the normal HTML/CSS fonts and want something new, fresh, and current, we can utilize Google Fonts. 

Google Fonts: -

Google Fonts is a Google online library that allows users to use several font families via a CDN (content delivery network) that is open to everyone.

The typeface we choose is an important aspect of any design. Google Fonts is a free online fonts service that lets users utilize a broad array of typefaces in our CSS file.

In 2010, Google Fonts was started as an engineering endeavour to advance the web and make it quicker.

Personal and commercial use of Google Fonts is both free. Thanks to the Google Fonts website, anyone may instantly select and use multiple fonts for their personal design needs.

Everyone uses Google Font, but mostly it is used by Graphic designers, Ui/UX designers, developers, web designers, bloggers, etc. Google Fonts can be used on wedding invitation cards, websites, posters, and books, these are a few, but its usage is a lot more.

Font creators, type foundries, and the design community from all over the world contribute with Google Fonts. These people and organizations create the fonts that we see on Google Fonts.

We should use Google Fonts because 

  • They are easy to implement.
  • There are more than 900 fonts from which we can choose to use for the developing website or anything.
  • The overall level of the fonts is improving.
  • Google Fonts can also be downloaded for usage in print.
  • The Google Fonts API enables using web-fonts to be easier and faster for everyone. The Google fonts have already been tested in a variety of browser settings.

We only need to add custom cascading style sheets (CSS) linked to our HTML document, which then references the font family of the chosen in the CSS style.

How to use Google Fonts?

We can use Google Fonts while developing the website or webpage in two ways.

The first way is by adding it to the <link> tag in the HTML file, and the second way is by using the @import rule. We will study both ways with the help of an example.

1)Adding to <link>tag in HTML document:-

How to use google fonts in CSS?

First, go to Google font's official website and select the font of our choice.

Then click on "select this style" and copy the link of the style we have selected.

And now paste that link in the <link> tag of the HTML document.

Syntax: -

<link rel = "stylesheet" href = "https://fonts.googleapis.com/css?family=Font+Name>  

Then we can use an external stylesheet or an inline style to apply the specified web font to an element.

Selector(id,class,tag)
{
	Font-family: ‘Name_of_Font’,’Name_of_font_family’;
}

Example: -

<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2 family=Cantarell&family=Caveat&family=Great+Vibes&family=Luckiest+Guy&family=Tapestry&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Cantarell&family=Caveat&family=Creepster&family=Great+Vibes&family=Luckiest+Guy&family=Rock+Salt&family=Tapestry&display=swap" rel="stylesheet">
<style>
h1{
  font-family: 'Caveat', cursive;
  font-size: 40px;
}
p
{
	font-family: 'Cantarell', sans-serif;
}
h2
{
	font-family: 'Rock Salt', cursive;
}
</style>
</head>
<body>
<h1>Using Google Fonts-Here we have used Caveat Font of Cursive Font-Family</h1>
<p>Here we have used Cantarell Font of sans-serif Font-Family</p>
<h2>Here we have used Rock Salt Font--6287287w92</h2>
</body>
</html>

Output: -

How to use google fonts in CSS?

So, in the above example, we have used multiple Google fonts by using it in the <link> tag and have applied to each selector or tag different Google Fonts to make it look different and understand how to use them.

2) Using import rule: -

We use the same ways here as we did for the <link> tag. Also, we can do, but instead of using the <link>tag here, we will be using the @import rule.

So firstly, go to Google Fonts, select the font of choice, and import it in the <style> tag.

Syntax: -

@import url(‘https://fonts.googleapis.com/css?family=Font_Family_name’)

Example: -

<html>
<head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Lobster+Two&display=swap');
h2{
color: blue;
}
 h1{
color: green;}
#Ex{
font-family: 'Lobster Two', cursive;
font-size: 30px;}
p{
color: purple;}
</style></head>
<body>
<center>
<h1> Example of Google Font using import rule </h1>
<div id ="Ex">
<h2> Here font-family is Lobster Two </h2>
<p> Hello This is an example of Google font using import here we have used lobster font of Cursive font family. </p>
</div>
</center>
</body>
</html>

Output: -

How to use google fonts in CSS?

In the above example, we have used only one font using @import, but as we did in the first example, likewise for import, also we can use multiple @import for styling purposes.



ADVERTISEMENT
ADVERTISEMENT