DEV Community

Cover image for Adding downloaded fonts in your React app
Roopali Singh
Roopali Singh

Posted on • Updated on

Adding downloaded fonts in your React app

Hola amigos👋,

There exist fonts which can't be found on Google Fonts.
And now you're left with no other option but to download and import them in the code on your own.

Lucky You🍀 It's not that difficult to add downloaded fonts in the React App.

You just need to follow these 4 steps:

1. Create a fonts folder in the src folder of your React app.

2. Add the downloaded fonts in the fonts folder created.

The Folder Structure would look something like this:

Folder Structure

3. In the index.css file, write the following lines of code:

/* In index.css */

@font-face {
  font-family: "GilroyRegular";
  src: local("GilroyRegular"),
    url("./fonts/Gilroy-Regular.otf") format("opentype");
  font-weight: normal;
}

/* Other font formats include:
'woff2', 'truetype, 'woff', 'embedded-opentype', and 'svg' */
Enter fullscreen mode Exit fullscreen mode

4. Import the index.css file in the index.js file.

// In index.js

import "./index.css";
Enter fullscreen mode Exit fullscreen mode

Now to use it, you just need to add the following css:

/* In any .css file */

.selector {
font-family: "GilroyRegular";
font-style: italic;
}
Enter fullscreen mode Exit fullscreen mode

😃Whoa!
We have successfully integrated the downloaded font in our webapp🔥

Task Completed

Top comments (0)