How to add custom fonts in React without Font CDN
3061
In this post, we will see how to add custom fonts to our react app.
Generally to add custom fonts we use CDN from an external source like Google Fonts etc. But the problem with them is they may increase the site startup time, as they download the fonts from the resource. Also if you're using the app in a low network area the font doesn't load sometimes. We will use the local font method in this post.
Adding the fonts to our local project
- First download the font you want to use
- Create a folder
fonts
insrc
folder - Add the downloaded font to the
fonts
folder - Open your
index.css
file and include the font by referencing the path.
@font-face {
font-family: 'Gilroy';
src: local('Gilroy'), url(./fonts/Gilroy.ttf) format('truetype');
}
Here for the post, I used Gilroy font you can use anything you want.