148

I am using Google fonts in a few of my pages and hit a wall when trying to use variations of a font. Example: http://www.google.com/webfonts#QuickUsePlace:quickUse/Family:Open+Sans

I am importing three faces, Normal, Bold, ExtraBold via the link tag. The normal face displays correctly, but I cannot figure out how to use the variants of the font in my CSS

I tried all of the following as attributes for font-family but no dice:

  • 'Open Sans Bold'
  • 'Open Sans 700'
  • 'Open Sans Bold 700'
  • 'Open Sans:Bold'

The google docs themselves do not offer much help. Anyone have an idea of how I should write my CSS rules to display these variants?

7 Answers 7

210

They use regular CSS.

Just use your regular font family like this:

font-family: 'Open Sans', sans-serif;

Now you decide what "weight" the font should have by adding

for semi-bold

font-weight:600;

for bold (700)

font-weight:bold;

for extra bold (800)

font-weight:800;

Like this its fallback proof, so if the google font should "fail" your backup font Arial/Helvetica(Sans-serif) use the same weight as the google font.

Pretty smart :-)

Note that the different font weights have to be specifically imported via the link tag url (family query param of the google font url) in the header.

For example the following link will include both weights 400 and 700:

<link href='fonts.googleapis.com/css?family=Comfortaa:400,700'; rel='stylesheet' type='text/css'>

For CSS2

<link href='fonts.googleapis.com/css2?family=Comfortaa:wght@400;700'; rel='stylesheet' type='text/css'>
8
  • 63
    this is partial truth, and is because if you dont assing the weight on the link css google wont download the proper "bold" format to achieve this you have to declare the "link href" as follow: <link href='fonts.googleapis.com/css?family=Comfortaa:400,700' rel='stylesheet' type='text/css'>
    – ncubica
    Jan 30, 2012 at 3:06
  • 4
    Is there any way to make the browser use weight 600 for old my old rules of "bold"? I think the 700 is too thick and don't want it anywhere on my site. Jan 16, 2013 at 10:35
  • What do you mean? I guess you should just change the bold to being 600?. Do you mean changing "bold" behaviour on <strong> and <b>? Jan 16, 2013 at 11:56
  • 2
    I am using @import url(fonts.googleapis.com/css?family=Open+Sans:400,300); as i cant access the html, and when i try and use the following... font-family: 'Open Sans', sans-serif; font-weight: 300; it doesnt change the font weight. ideas? Nov 11, 2015 at 14:01
  • 2
    So then if I can use normal CSS for this, why does Google let me decide which weight I want to use?
    – dawn
    Dec 19, 2018 at 5:13
33

Here's the issue: You can't specify font weights that don't exist in the font set from Google. Click on the SEE SPECIMEN link below the font, then scroll down to the STYLES section. There you'll see each of the "styles" available for that particular font. Sadly Google doesn't list the CSS font weights for each style. Here's how the names map to CSS font weight numbers:

Thin            100     
Extra Light     200
Light           300
Regular         400
Medium          500
Semi-Bold       600
Bold            700
Extra-Bold      800
Black           900

Note that very few fonts come in all 9 weights.

12

font-family:'Open Sans' , sans-serif;

For light: font-weight : 100; Or font-weight : lighter;

For normal: font-weight : 500; Or font-weight : normal;

For bold: font-weight : 700; Or font-weight : bold;

For more bolder: font-weight : 900; Or font-weight : bolder;

3
  • Great. But can the font be lighter than font-weight : 100 ?
    – John Max
    Jul 21, 2016 at 9:07
  • 3
    No, minimum value is 100 only and maximum value is 900.
    – user6097020
    Jul 25, 2016 at 12:34
  • 4
    This is not correct, the following values are to consider: light: font-weight: 300; normal: font-weight: 400; semi-bold: font-weight: 600; bold: font-weight: 700; extra bold: font-weight: 800;
    – geraldo
    Nov 18, 2018 at 10:57
5

The API has been updated, now you have to import the desired font-weight using ":wght@700"

Ex: "https://fonts.googleapis.com/css2?family=Inter:wght@700&display=swap"

source: https://developers.google.com/fonts/docs/css2

3

In case anyone is looking for latest format with multiple font families + weights, see below (ex. w/ Open Sans + Roboto)

https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,800&family=Roboto:wght@500&display=swap

Note that the latest version of google fonts web interface has bad UX for displaying the code sample. There is a 'selected families' panel which displays and then disappears, and it overlaps the font variations 'add' buttons (the plus / minus signs), which are also located on the right. The solution, which is not intuitive, is to reload the page.

2

you can use the weight value specified in the Google Fonts.

body{
 font-family: 'Heebo', sans-serif;
 font-weight: 100;
}
0
0

I experienced a similar problem in lec 72 of angela yu's course and we have to define the font-weight along with font-family

h1 {
font-family: 'Montserrat', sans-serif;
font-weight: 900;
font-size: 3rem;
line-height: 1.5;
 }

Not the answer you're looking for? Browse other questions tagged or ask your own question.