Front-End & Daily

How to use font-stretch with Google Fonts variable fonts in CSS

How to use font-stretch with Google Fonts variable fonts in CSS

Variable fonts that allow free setting of weight and width.

Even though I loaded variable fonts from Google Fonts, "font-stretch" and "font-variation-settings" don't work! This happens often, right? (No it doesn't)

For example,
when you want to set
"Noto Serif Display"
to "Regular 400 italic" with
"font-width: SemiCondensed"

Normally, you select and load "Regular 400 italic"

How to use variable fonts with Google Fonts

You specify the CSS like this, but

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+Display:ital@1&display=swap');

.notoserif {
	font-family: 'Noto Serif Display', serif;
	font-size: 4rem;
	font-stretch: semi-condensed;
}

As it is, "font-stretch" will not work.

(Reproduction)

font-stretch: unspecified

Variable Fonts

font-stretch: semi-condensed;

Variable Fonts

How can I use font-stretch?

What about the file size when multiple fonts are loaded?

I will explain these points.

Table of Contents

Correct loading method

The correct way is

  1. Open "Type tester"
  2. Change to your preferred settings
  3. Click "Select +" on the one that appears below
  4. It has been added to the right, so load it with this.

How to use variable fonts with Google Fonts

Then, we confirmed that "font-stretch" is working!

For comparison

font-stretch: unspecified

Variable Fonts

font-stretch: semi-condensed;

Variable Fonts

File size when adding various font-widths

When you want to use various font-widths (font-stretch) like normal (100), semi-condensed (87.5), or condensed (75), you need to load all of them.

Loading multiple widths of variable fonts with Google Fonts

I was curious, so I investigated: Does the page size increase accordingly?

① normal only

Loading variable fonts with Google Fonts

At this time, the size of the loaded font was 14.2KB.

Size of the loaded font

② Added SemiCondensed

Loading variable fonts with Google Fonts

At this time, the size of the loaded font was 26.9KB.

As expected, it increased.

Size of the loaded font

③ Added Condensed

Loading variable fonts with Google Fonts

For some reason, it was unchanged from before.

Size of the loaded font

※ Verified with cache cleared.

"normal" needs to be loaded separately

Other than that, if you load even one, the size does not change no matter how many you add.

Loading variable fonts with Google Fonts

Regarding Weight, the first one increased in size, but subsequent ones did not change.

Loading just this amounted to 86KB.

Loading variable fonts with Google Fonts

Therefore, even when you want to use multiple styles, you don't seem to need to worry too much about file size.

It might differ depending on the environment and font, so please use it while observing the situation.

Comments

After reviewing the content, we will publish it, omitting personal information.

Enter your name and email address

Please enter if you would like a reply by email.

The personal information provided will not be disclosed. It will only be used for replies.

It will be sent directly. Please confirm and "Send".

If this was helpful, we appreciate your support!
The support received will be used for childcare.

Send support with OFUSE


Or buy something from the buttons below to support us
(You don't have to buy the linked product.)

Amazon

Rakuten Ichiba

Yahoo! Shopping

PR

As an Amazon Associate, "Ken" earns from qualifying purchases.

Share

Twitterでシェア Facebookでシェア LINEでシェア Share on Hatena Bookmark