1

I downloaded some fonts and am storing them in my src folder:

├── src
│   ├── fonts
│   │   ├── font.ttf
│   ├── components

Then I tried to add them using font-face but I can't figure out why it's not working. Is there a specific place you're supposed to put them in your react project?

Right now I'm declaring the font in the same file where I'm trying to use it:

@font-face {
  font-family: "MyFont";
  src: local("MyFont"), url("path/to/font.ttf"),
    format("truetype");
}


p {
    font-family: 'MyFont'
}

When I do this it just reverts to my system's font, overriding the fonts declared in my index.scss file:

html,
body {
  font-family: "Roboto", "Arial", sans-serif;
}

body {
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: "Roboto", "Arial", sans-serif;
}

Is there a specific file I need to declare the font family? Am I importing it wrong? The file path is correct, so I'm not sure what's happening. I downloaded the fonts I wanted and copied the files into my src/fonts directory. Is that where the issue is coming from?

Yehuda
  • 27
  • 15
  • Does this answer your question? [How to add fonts to create-react-app based projects?](https://stackoverflow.com/questions/41676054/how-to-add-fonts-to-create-react-app-based-projects) – Kundan Dec 07 '22 at 03:41
  • his answer is still not working for me. Also doesn't explain why my `html, body` are reverting to system font. – Yehuda Dec 07 '22 at 04:04

0 Answers0