Answer the question
In order to leave comments, you need to log in
How to properly include fonts in ReactJs?
0
Tell me, please, where is it better to add fonts: in src or public? Is there any difference in this? And how to connect them to the project? I just started learning React, I'm trying to create my own spa and I can't figure out how to properly include fonts. I will be grateful for help)
Answer the question
In order to leave comments, you need to log in
For example, you want the font Source Sans Pro . Install @fontsource/source-sans-pro package . In a file main.js
or main.ts
import it:
or if you need a specific range of unicode characters:
import '@fontsource/source-sans-pro';
import '@fontsource/source-sans-pro/cyrillic.css';
Fonts must be included in index.html, which is in the project. And you can place them anywhere, even in the public folder, even just connect with cdn. In .jsx, .tsx files, you do not need to include fonts, this can lead to flickering when updating some components or a page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question