Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use multiple Google Fonts in a webpage?

Tags:

html

css

I know this is a short question, but how do you use multiple custom Google Fonts, i.e Baloo and Roboto, in the text? In this example the text should be Roboto and headings should be Baloo. Thanks for your time.

like image 888
scdmn jeh Avatar asked Mar 02 '17 18:03

scdmn jeh


People also ask

How do I use multiple fonts in Google Fonts?

Then, add the family= URL parameter, with one or more font family names and styles. Note: Replace any spaces in the font family name with plus signs ( + ). To request multiple font families, separate the names with a pipe character ( | ). Requesting multiple fonts allows you to use all of those fonts in your page.

Is it better to link or import Google Fonts?

Should I use <link> or @import ? # Loading Google fonts in the HTML reduces the critical request depth and speeds up page load Always import your fonts from HTML, not CSS.


3 Answers

You click "select this font" for each font you want to use, and google will give you a single link tag with multiple fonts. You can also include multiple link tags for each font.

h1 {
  font-family: Baloo;
}
h2 {
  font-family: Roboto;
}
<link href="https://fonts.googleapis.com/css?family=Baloo|Roboto" rel="stylesheet">
<h1>Baloo</h1>
<h2>Roboto</h2>
like image 157
Michael Coker Avatar answered Oct 02 '22 06:10

Michael Coker


google fonts is now using css2 and the answers above are outdated.

the solution using css2 would be: https://fonts.googleapis.com/css2?family=Baloo&family=Roboto

source: google fonts doc for css2

like image 41
choongmanee Avatar answered Oct 02 '22 06:10

choongmanee


  1. Go to https://fonts.google.com/

  2. Search for say Roboto - https://fonts.google.com/specimen/Roboto

  3. Hit "select this font" and you'll get a link to add to you html like this:

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

Note: You can also get one line with multiple fonts by piping the families.

  1. Add this link(s) in your <head> tag

  2. Use CSS to select the font with font-family.

See example below:

h1{
  font-family: "Baloo"
}

p{
  font-family: "Roboto"
}
<!DOCTYPE html>
<head>
<link href="https://fonts.googleapis.com/css?family=Baloo|Roboto" rel="stylesheet">
</head>

<body>
    <h1>Baloo</h1>
    <p>Roboto</p>
</body>    
like image 45
Turnipdabeets Avatar answered Oct 02 '22 05:10

Turnipdabeets