Languages

React - can't change Google Fonts font-weight property

0 points
Asked by:
FryerTuck
649

How can I change Google Fonts font-weight property?

I've imported the following font into my index.html 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=Mitr:wght@200&display=swap" rel="stylesheet">

and now, when I try to change font-weight of my title element in .css file like this:

.title {
    font-weight: 500;
}

it doesn't change anything.

So my question is how can I change the font-weight of the Google Font to make the .title element bold?

1 answer
0 points
Answered by:
FryerTuck
649

Firstly, you need to import all the font-weight property values you want to use in your project.

You've only imported the font-weight: 200 (as you can see wght@200 in the 3rd link element).

Solution

1. Go to the Google Fonts once again and select all the font-weight property values you want to use in your project:

React - select multiple Google Fonts font-weight property values
React - select multiple Google Fonts font-weight property values

2. Import them - you can use the <link> elements as you did it in your project:

<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=Mitr:wght@200;300;400&display=swap" rel="stylesheet">

Note:

In the example above, you can see 3 different font-weights (wght@200;300;400). Now you can use font-weight: 200, 300 or 400 in your project.

 

See also

  1. React - import Google Fonts

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join