Make Chrome use an external font in CSS

It took me a long time to realize that Chrome always prefers locally installed fonts over a font with the same name as it is associated in css (see also https://stackoverflow.com/a/16801/ ). My problem is how to understand, make Chrome not do this.

On my page https://www.amon.cc/ I use "Roboto Light" from Google Fonts ( https://fonts.google.com/specimen/Roboto ), for example:

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

In my CSS file, the font is declared as follows:

 body{ ... font-family:Roboto,...; font-weight:300; .... } 

What works great in FF, IE, Edge:

Font in FF, IE, Edge

But in Chrome, the font is always thicker:

Font in Chrome with locally installed font

Cause. On my private Windows 10, as well as on a business computer, the Roboto font is pre-installed on Windows: Robot Regular, Robot Condensed. But there is no Roboto Thin or Robot Light, so it seems that Chrome has a backup of Roboto Regular.

When removing a Robot font from Windows, Chrome uses the declared web font and displays it the way I want it. I could not figure out how to “force” Chrome to not use the local installation and use it on the CDN instead.

However, Chrome can display the Roboto font in all different ways on the website https://fonts.google.com/specimen/Roboto (even with my local Robot font), I could not understand how this was done.

+6
source share
1 answer

You can rename the font to your CSS and still use the remote woff file. For instance:

 @font-face { font-family: 'RobotoBis'; font-style: normal; font-weight: 300; src: local('Roboto Light'), local('Roboto-Light'), url(http://fonts.gstatic.com/s/roboto/v15/Pru33qjShpZSmG3z6VYwnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF; } @font-face { font-family: 'RobotoBis'; font-style: normal; font-weight: 300; src: local('Roboto Light'), local('Roboto-Light'), url(http://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000; } h1 { font-family: RobotoBis; } 
 <h1>Hello world !</h1> 

But the dark side of this method is that Google may change the font URL in the future (which is mostly likely). Therefore, you have your own font files to avoid this problem.

And of course, it can only be applied to your own websites and where you can customize CSS ...

+4
source

All Articles