Can't set font-weight on Google Fonts - css

This question has been asked quite a number of times, but none of them works for me. For example:
Google fonts font-weight of 100 is not working. (I don't have the font I want to use already in my system.)
Why is google font weight not working?. (I'm not using it in a heading, just a regular paragraph.)
I used Google Fonts with the #import like so:
#import url('https://fonts.googleapis.com/css?family=Rubik');
body {
font-family: 'Rubik', sans-serif;
}
The typeface shows up, but I can't do anything with the weight. The <strong> tags aren't displayed bold. The font-weight property in the CSS isn't working. Not even overriding it in browser's inspector changes anything.
Update
The thing seems to only work on Gecko-based browsers, like Firefox.

The answer is that the Google font isn't calibrated to carry all of the weights you want with it.
Some of the browsers may display 'thicker' or 'thinner' type, but they are tricking you. They are doubling up the normal font to simulate what you are asking for when there is no actual weight of that type available. The ones that do that are trying to be nice, but these days it is more confusing than helpful. According to your code snippet, you have:
#import url('https://fonts.googleapis.com/css?family=Rubik');
vs
#import url('https://fonts.googleapis.com/css?family=Rubik:300,400,500i,900,900i');
(Google Fonts UI 2017 - may look different in the future but the concept is the same for any font service)
Many fonts only have 1 weight.

Here's a list of all of the possible names for font-weights;
Thin 100
Extra Light 200
Light 300
Regular 400
Medium 500
Semi-Bold 600
Bold 700
Black 900

I have had also issues to get the weights working, even though I had properly copied the HTML code from google and put into my head.
Solution:
I used the #import function by adding it my CSS and now everything works without issues. Seems that #import is more robust or less conflicting with wp themes.

I had the same issue.
For me the problem was that my link to bootstrap was placed after my link to styles.css in my html, and thus bootstrap overrode the style for h1.
The solution was simply to put the link to styles.css after the link to bootstrap in my html. :)

I had the same problem until I found out that you can not change the font weight of the body.
you have to target the exact tag you want to change the weight
eg.
Check this code out

I had the same problem: i noticed that it occurred when you import the font on the css file like:
#import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
So in order to solve i just imported all the font weight from the html file and then use the font weight and the font family as usual in the css file:
<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
Doing like this i was able to solve my problem. Noticed that you can't specify the font weight in the body tag but you have to do in the single html tag like h1 h2 h3 p ecc

The no. of fonts weights you require select them all.This will look like this:
#import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght#0,400;0,700;1,300&display=swap');
Now you can use all this font-weights.

Related

Component CSS #Import conflict

In my login component's CSS, I am importing the following font:
#import url(https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght#1,600&display=swap);
In another component in the system, I would like to use this same font but I do not want it applied with italics. I am importing it in that component's CSS as:
#import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400);
In this case, the component is rendering it as if the login page import was being used (the font appears in italics and at 600 font weight).
Until I refresh the page. If I do a refresh, it appears properly at 400 without the bold.
I have tried applying:
font-variation-settings: normal;
To the div containing the text, this has no effect.
What am I doing wrong?
Could be something related to the caching of css and fonts?
Maybe here you can find the answer.
LINKs:
Preloading fonts using angular CLI
Browser Caching of CSS files

Why do Google fonts look crisp on google's site but not on mine

I'm using josefin sans font from Google fonts. It looks crisp and sharp on their website and consistently so for all browsers. But when I import the fonts to my site via linking to provided css file , they look thin and blurry. I know about some fixes you can do, but they don't work consistently. why does this happen? Does putting these fonts locally help ?
Each font (or almost each) hash a few "sub-fonts" if you will which are slight variations of the original font. Make sure you select the one you really want. Look at the variations:
Josefin Sans
Did you make sure to include all of the needed font files?
Your CSS link should look something like this:
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans:300,400,600' rel='stylesheet' type='text/css'>

How to get smooth Google fonts?

I formerly used the plugin WP Google Fonts, which hasn't got my requested feature, either.
For now I'm using Google fonts with an implemented feature in the currently used theme. The fonts are embedded without trouble and they are shown correctly.
For now there are plenty blogs with nicely readable smooth fonts for HD displays and I want those fonts, too. As seen in my WordPress, it is capable of showing them, example below:
There are no sharp edges, no pixels, etc. That's how I would like it.
I selected "Droid Sans" currently as the font for my articles. But this font shows up WITH sharp edges and pixelated. Example below:
(Please note that opening this picture in a new tab shows the issue much more clearly.)
Is there anything to make this look smooth and cool?
Is it just the wrong font? I'm not bound to it and tried some others fonts. They all seem to have those sharp edges. If you know a font for compare, please note it.
Is there a CSS snippet I have to add?
Is it a server-sided configuration?
How can I achieve smooth fonts in my articles page?
It can depend on what browser you are using.
I tend to use:
-webkit-font-smoothing: antialiased;
or if you have blurry bold text:
-webkit-filter: blur(0.000001px);
on webkit browsers.
Alternatively, you can add a text-shadow to make the text seem smoother
html, html a {
text-shadow: 1px 1px 1px rgba(0,0,0,0.004);
}
I also recommend you try different font sizes as some custom fonts will only look good at certain sizes.
Other than that, there isn't much you can do apart from use another font. Google Chrome did just release an update for smoother fonts. It might also be useful to look at svg fonts:
Google Fonts & http://www.fontspring.com/demos/svg-vs-woff/
I solved this issue, using google fonts like SVG:
<style type="text/css">
#import url('https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic');
</style>

Fonts turning bold, not supposed to

Okay, I'm not going to post the entire css code for your own sake lol, but it's here http://pattersoncode.ca/incls/style.css
Anyway, I don't know whether it's a problem with my browser (Safari 7) but whenever the page fully loads, all the writing turns bold, and it looks out of place.
As you can see, I've set font-weight: normal !IMPORTANT on many areas of my code to see if that would solve it, but it didn't.
I guarantee you have a LABEL or H2 that isn't closed properly. You have only have only 2 elements with a bold definition: LABEL and H2 If you have closing tags missing or out of sequence, the style will cascade in the document, making everything bold.
Looks like Google's #font-face declaration is overwriting your own font-weight. That may be because Google's Font CSS comes right AFTER your style.css. Try placing Google's font-face css BEFORE your style.css, like this:
<link href="http://fonts.googleapis.com/css?family=Muli:300" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="http://pattersoncode.ca/incls/style.css">
Then reset overwrite font-weight again in your style.css

Font Weight with Different Fonts

Is it possible to mate a particular font family to a specific font weight?
For instance, if I use Francois One from Google Web Fonts, it seems to look good at font-weight:500. Unfortunately, though, if a web browser never downloads Francois One, or doesn't have the capability to see web fonts, then font-weight:500 means most users won't see a bold font.
I want bold on all browsers, but for those who actually download Francois One, I want them to see font-weight:500.
EDIT: If you import the Google Font via <link> in the html document, I think you can specify which weight you import for that particular font:
<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Francois+One:500' type='text/css' />
It's about 10 months too late but I stumbled across your question in search of a similar fix and found a closely-related question. I suspect you have found a solution or another method, but just in case: CSS: set font weight depending on fallback font
Apparently, it can't be done without Javascript intervention, and at that point I think it would be overkill. I hope this finds you some use! I'd be interested if you were able to solve this.

Resources