Font weight ignored in Chrome
Asked Answered
M

9

45

I created a fiddle trying to use Open Sans font with font-weight 300:

HTML

<span class="demo">example</span>

CSS

.demo {
  font-weight: 400 !important;
  font-family: 'Open Sans' !important;
  font-style: normal;
  font-variant: normal;
}

I use Google fonts to define the CSS

I can see a difference in Firefox (Ubuntu 13.10) when rendering at font-weight: 300 (light) and at font-weight: 400 (normal) but none in Chrome (Version 33.0.1750.117 ), where everything looks like it's rendered at font-weight:400. Am I doing something wrong or is there a bug in Chrome? Is there any known workaround?

Update:

There is definitely something wrong with chrome I have two instances of the same page open in 2 different windows in Chrome. One is rendering the font ok (300 weight corresponds to the light variant) and one is not (300 weight is the same as the Normal variant). Any clues? I've made sure to refresh the page in each tab so they are actually the same page.

Update 2: Attached screenshot: of the bug: Chrome font rendering bug

Update 3 This is not a duplicate of this. In that question the problem is that "Arial Black" and "Arial" are different fonts actually. In my case Open Sans is the only font and the problem is Chrome picking up the incorrect weight some times. As you can see from the screenshots, Chrome is not consistent with the font rendered even between two instances.

Multivalent answered 24/2, 2014 at 23:2 Comment(8)
If you whack the font-size up to 7.5em, you'll notice that there is a slight difference in the font-weight (I am using Chrome). If you add -webkit-font-smoothing: antialiased; you'll see the difference even more.Plumbago
Instead of having all of those css calls, why not just use the google font import, i.e. @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,700,700italic,800);Suzette
@Plumbago I notice no difference both at 7.5em and using -webkit-font-smoothing: antialiased.Multivalent
@Suzette I'm already using Google's font import as an external resource in the doodle.Multivalent
Do you happen to have Open Sans installed locally on your system? I've had some issues with the font weight before and after I deleted it from the system, everything worked fine.Ailment
@LéoLam Thanks! Worked the second I deleted it locally.Titbit
@0x2D9A3 Thanks for the feedback! I've posted it as answer since it worked for more than one person. I wonder if it only occurs on Linux...Ailment
@LéoLam Nope, I am on Win7.Titbit
R
41

Add this to your CSS:

* {-webkit-font-smoothing: antialiased;}
Renascent answered 17/12, 2014 at 14:49 Comment(2)
Thanks, it works. Is there any explanation for that?Lackaday
Works for me too. Know more about font smoothing here: szafranek.net/works/articles/font-smoothing-explainedCrumpton
P
15

This seems to be a Chrome/Chromium bug, caused by having the font installed locally on your system. Other browsers don't seem to suffer from this issue.

So far, it seems to occur on Linux and Windows (confirmed).

For some reason, it will just load your local font and ignore any of your font-weight rules, even if they're !important. It won't even be consistent with itself: the font weight can change randomly between tabs and page reloads.

The simplest workaround is to remove the font, but that could be an issue if you need it for something else.

You might also try renaming the font to something else in order to force Chrome to use your web font and honour your CSS font rules.

Paymar answered 30/12, 2014 at 11:12 Comment(6)
the problem is "what if the user has the font installed"? And "try renaming the font to something else" for Google's Open Sans is not so trivial.Schismatic
You'd have to get Chromium to fix this issue. (I don't know if it's been fixed recently.) As for renaming the font, it's as trivial as downloading the font and changing the font name when you reference it in your CSS. It's not as easy as simply adding a <link> to Google's CSS but it's not that complicated either.Ailment
Renaming the font reference won't work on Chrome 56.0.2924.87Sayer
Ahh, yes. That's it. It renders perfectly on other browsers and devices, and the font-weight is set to 400 yet it's rendering as 700. Thanks!Mariettemarigold
I ran across this as well. The solution for it to work well in Chrome is to not use @import but instead include the file css in the <head> section. Also see my answer.Convention
Just to add that the bug is also there on Mac OS. Details: Chrome Version 89.0.4389.82 (Official Build) (x86_64) and macOS Catalina Version 10.15.6 (19G73)Unreason
M
8

I was having this issue with a variable font. It was solved by defining a font-weight range in the font-face definition.

@font-face {
  font-family: …;
  font-weight: 1 999;
  src: …;
}
Madrigalist answered 25/11, 2021 at 14:40 Comment(2)
wow, could not find this anywhere else. saved me, thank you!Konyn
This was the only solution that worked for meBabb
K
3

Try changing the font family to 'Open Sans Light', sans-serif;. I had the same problem and this worked for me.

Knowledge answered 2/7, 2014 at 13:42 Comment(1)
This makes the Google font not working on any browser for me: 'Open Sans Light' is not recognized and all browsers fall back to the installed sans-serif I believe.Schismatic
A
1

i overlaid them on top of each other and they look good on osx chrome.

font-weight: 400 !important;

beneath

font-weight: 300 !important;

http://jsfiddle.net/gpmXe/22/

Attraction answered 25/2, 2014 at 0:28 Comment(2)
The still look the same to me on Linux.Multivalent
On Win Chrome as well for meSchismatic
C
1

For me the solution was to include the CSS in the head-section instead of using @import inside the stylesheet.

<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,700;1,400&display=swap" rel="stylesheet">
Convention answered 16/4, 2020 at 12:14 Comment(0)
G
1

In HTML use this instead of using it in CSS. Best Solution 👍

<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,700;1,400&display=swap" rel="stylesheet">

Doc for ital & wght

Giraldo answered 10/9, 2022 at 6:56 Comment(3)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Riancho
Wouldn't recommend this if your site needs to be GDPR compliantGorged
This is definitely not the best solution and, moreover, cannot be used within the EU or countries that protect users' data.Nellienellir
D
0

My solution is download and install all the weight types of the font on your machine, or don't install it at all. That's odd solution, but works for me.

Door answered 12/1, 2017 at 4:17 Comment(0)
H
0

This is probably obvious to most of you, but I was having this issue and in my case it turned out I was simply overriding it with the font attribute in the same selector:

    selector {
        font-weight: bold;
        ...
        font: inherit;
    }

Moving the font-weight to below the font attribute fixed it. I guess that's basic css, but I didn't remember that the font attribute overrides the font-weight attribute like that. I think I meant to use font-family instead of font, and that caused the problem.

Heinrike answered 7/9, 2023 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.