Google Font not working on Safari
Asked Answered
U

11

33

I'm working on making my site look the same under Safari and Chrome. In Chrome it looks exactly how I want it to. The major problem is that Google Font doesn't seem to be loading under Safari. Because I'm using the exact code given on the Google Font site, I can't understand why Safari won't fetch it. Is it just incompatible with Safari and I have to rely on a fallback font?

The site can be found here

Ure answered 5/6, 2014 at 13:39 Comment(5)
For the nav, you have an empty ul tag in the menu.Winy
@NickR +1 Thanks, actually it was supposed to be the ending </ul> tag.Ure
Ah it turns out that it is actually working. But you have font-weight:bold on the <ul> tag, which is causing the font to look so different in Chrome vs Safari - if you have a look at this image of the site in Safari with font-weight:bold turned off : i.imgur.com/tBvw25F.png Basically don't use the light version of the font and try and make it bold in CSS, instead use the bold 700 version of the font - google.com/fonts#UsePlace:use/Collection:NunitoWiny
@NickR Thank you! It does look better now. I've taken the bold weight off, it's closer to what I want it to look like. Is it normal that fonts with exactly same config look different between browsers? Or does it stem from my poor CSS skills?Ure
I think this article explains it quite nicely - alistapart.com/article/say-no-to-faux-boldWiny
S
10

For some odd reason I have experience this on some web fonts from Google...when this has happened I usually get them to my server and/or convert them in fontsquirrel....Safari should be able to take TTF Files no matter what ver:

Nunito TTF ver

Stupor answered 5/6, 2014 at 13:54 Comment(3)
Google Fonts generally work in Safari, so something else must be happening... what version of Safari? How do you know it's not working -- are you seeing an error in your dev tools console? (For how it's used in your nav header, the characters look almost indistinguishable from most sans serif fonts anyway).Racklin
@BenPoole agreen with Ben ...maybe you can screenshot your Safari and see how it looks?Stupor
Just doing a bit of investigating...It's being served up as a .woff file - fonts.googleapis.com/css?family=Nunito:300 - This says caniuse.com/woff that Safari 5.1+ can use .woff files, although I just checked OPs site in 5.1.7 (Windows Safari) and the font isn't working.Winy
P
41

Your CSS should not only contain

font-family: 'Source Sans Pro', sans-serif;

it should also have values for FONT-STYLE and FONT-WEIGHT:

font-family: 'Source Sans Pro', sans-serif; 
font-weight: 900; 
font-style: italic;

in case you use a font that contains those values like for example: https://fonts.googleapis.com/css?family=Source+Sans+Pro:900italic

Porcine answered 27/11, 2015 at 14:14 Comment(2)
Yes adding font-style and font-weight worked for me. I was using an italic version of a font imported into a sass file, it worked on Chrome, but needed the font-style and weight for safariAnthropologist
Holy crap I've spent hours today trying to figure out why a custom font wouldn't load on MacOS/iOS - font-weight and font-style were already declared in the @font-face declaration but finally adding this to the main CSS declaration where the font is defined finally made it load correctly on Safari. Thanks for saving me from bashing my head against the wall!Damico
A
17

A 2018 update

I've had this problem in the past and I've had to resort to the option of providing more font file formats. I was a bit surprised to encounter it again in 2018. But it turned out that my problem was not with file-formats but simply with not requesting and specifying the correct font weights.

If we don't customize the URL for requesting this font from Google our link tag will look like this:

<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">

Let's have a look at what is inside that requested URL. It's going to contain several font-face rules looking something like this:

/* latin */
@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 400;
  src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v11/6xK3dSBYKcSV-LCoeQqfX1RYOo3qOK7l.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

Notice the font-weight attribute. It's specified as 400 which is a "normal" weighted font. Some browsers are able to take this font and turn it into a bold and still look half way decent. This is called "faux bold". It's never going to look as good as a hand crafted bold font though. And on some browsers, notably mobile Safari, it's going to fall down flat and look horrible.

The remedy is to request and specify the actual font weight variants you want to use. In my case it looks like this:

Screenshot from Google Web Fonts

This will produce the following link tag:

<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700&amp;subset=latin-ext" rel="stylesheet">

If you look at the contents of that URL you'll find that there are now entries for font-face rules font-weight: 700 in there.

Now if I want to use the bold version of this font for my h1 tags I'll use the following CSS.

h1 {
    font-family: 'Source Sans Pro', sans-serif;
    font-weight: 700;
}

Most browsers will automatically set h1 as font-weight: bold. If I want to take advantage of that default setting I have to provide my own font-face rules. I can do this by simply duplicating the font-face rules supplied by Google, exchaging font-face: 700 for font-face: bold and putting those changed rules in my own css.

So this rule:

/* latin */
@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 700;
  src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(https://fonts.gstatic.com/s/sourcesanspro/v11/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

Would become this:

/* latin */
@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: bold;
  src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(https://fonts.gstatic.com/s/sourcesanspro/v11/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

Now an h1 tags with font-family: 'Source Sans Pro' will be using the correct font variant. If you want a more in depth read check out this 2012 A List Apart article.

Augustaaugustan answered 12/9, 2018 at 9:17 Comment(1)
I don't know why, but my link doesn't work <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Calibri:ital,wght@0,400;0,700;1,400;1,700&display=swap" />, but if I copy the CSS, then it works well.Bemba
H
13

If you are using an @import code in the css like this

enter image description here

delete it and use link in head tag

enter image description here

Hard answered 27/4, 2016 at 8:54 Comment(1)
Big help!! Thank you!Carminacarminative
S
10

For some odd reason I have experience this on some web fonts from Google...when this has happened I usually get them to my server and/or convert them in fontsquirrel....Safari should be able to take TTF Files no matter what ver:

Nunito TTF ver

Stupor answered 5/6, 2014 at 13:54 Comment(3)
Google Fonts generally work in Safari, so something else must be happening... what version of Safari? How do you know it's not working -- are you seeing an error in your dev tools console? (For how it's used in your nav header, the characters look almost indistinguishable from most sans serif fonts anyway).Racklin
@BenPoole agreen with Ben ...maybe you can screenshot your Safari and see how it looks?Stupor
Just doing a bit of investigating...It's being served up as a .woff file - fonts.googleapis.com/css?family=Nunito:300 - This says caniuse.com/woff that Safari 5.1+ can use .woff files, although I just checked OPs site in 5.1.7 (Windows Safari) and the font isn't working.Winy
S
8

My case was that I used font name without quotes. So just change

body{
    font-family: roboto, Arial, sans-serif;
}

to

body{
    font-family: 'roboto', Arial, sans-serif;
}

Chrome works perfectly without quotes, but Safari doesn't.

Schmit answered 5/12, 2014 at 13:13 Comment(1)
funny thing - had the problem with the same fontGwenette
V
6

I had a case where a Google Webfont (Londrina) did not show up in Safari (for Windows), because I used text-rendering: optimizeLegibility;. After removing that, it was fine.

Example: http://codepen.io/julia-r/pen/gagbdy

Vc answered 29/9, 2015 at 13:37 Comment(2)
I don't have a new question, I just wanted to mention another reason, why a font might not show up. Maybe I didn't make that clean enough...Vc
Not quite sure why anyone would think this was a new question. Over-zealous copypasta?Aeroneurosis
J
4

Twas happening in 2021 for me. Had to switch the ampersand in the URL to &amp;.

<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@300;700&amp;display=swap" rel="stylesheet">

Janik answered 14/4, 2021 at 20:39 Comment(2)
Same for me, 2022 and this was the solution that worked!Intransitive
This completely fixed my solution.Clardy
B
0

The only way that solved this problem for me was by updating the link in the head from this:

<link href="https://fonts.googleapis.com/........" rel="stylesheet">

...to this:

<link href="https://fonts.googleapis.com/........" rel="stylesheet" type="text/css" />

My solution was adding the type attribute with a value of text/css to the link element in the head of the file.

Hope that helps someone.

Barvick answered 26/4, 2022 at 16:13 Comment(0)
O
0

Also we need to pay attention to CSP if we have it configured. In Firefox and Chrome Content Security Policy was asking for font-src but Safari (both macbook and ios) was asking for style-src. Based on your personal policy for fonts, these settings must be adapted per browser as well.

Orose answered 19/11, 2022 at 12:29 Comment(0)
B
0

today i had a similar problem. Page in Safari (in chrome, firefox, edge all work fine). Problem has been solved.

In order for the font to display in safari, we need to change the font link:

<link href="https://fonts.googleapis.com/css?family=Montserrat:thin,extra-light,light,100,200,300,400,500,600,700,800" rel="stylesheet">

to this:

<link href="https://fonts.googleapis.com/css?family=Montserrat:thin,extra-light,light,100,200,300,400,500,600,700,800&display=swap" rel="stylesheet">

we nedd to add "&display=swap" in the end of the link.

the rest of the css code looks like this:

html, body {font-family: 'Montserrat', sans-serif; font-size: 20px; font-weight: 300; font-style:normal;}
Bianca answered 19/3, 2023 at 16:18 Comment(0)
T
0

I was having the same issue and mine was fixed by adding 2 after css in the URL.

BEFORE

https://fonts.googleapis.com/css?family=Chivo:wght@400;500;600;700&amp;display=swap

AFTERWARDS

https://fonts.googleapis.com/css2?family=Chivo:wght@400;500;600;700&amp;display=swap
Therron answered 24/3, 2023 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.