-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to import and use local fonts #1276
Comments
You should not put to variables.css anything except variables, otherwise the code will be duplicated multiple times - depends on how many The best place for custom fonts is your top level react component ( Then you need to define About path to fonts, you can use the same modular/component approach here, just put them to the components folder and use relative path in Example: /src/component/Layout/
├── /fonts/
│ ├── /Roboto-Regular.woff2
│ ├── /Roboto-Regular.woff
│ ├── /Roboto-Bold.woff2
│ └── /Roboto-Bold.woff
├── Layout.css
├── Layout.js
└── package.json /* src/components/Layout/Layout.css */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src:
local('Roboto'),
local('Roboto-Regular'),
url(./fonts/Roboto-Regular.woff2) format('woff2'),
url(./fonts/Roboto-Regular.woff) format('woff');
}
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 700;
src:
local('Roboto Bold'),
local('Roboto-Bold'),
url(./fonts/Roboto-Bold.woff2) format('woff2'),
url(./fonts/Roboto-Bold.woff) format('woff');
}
html {
font-family: 'Roboto', sans-serif;
}
/* ... */ |
@frenzzy thank you so much for your help. It still does not work, I followed your steps (font paths + declaration) as: @font-face {
font-family: 'TPHero';
font-style: normal;
font-weight: bold;
src:
local('TPHero Bold'),
local('TPHero-Bold'),
url(./fonts/TPHero-Bold.otf) format('otf');
}
@font-face {
font-family: 'TPHero';
font-style: italic;
font-weight: normal;
src:
local('TPHero MediumItalic'),
local('TPHero-MediumItalic'),
url(./fonts/TPHero-MediumItalic.otf) format('otf');
}
@font-face {
font-family: 'TPHero';
font-style: italic;
font-weight: 600;
src:
local('TPHero SemiBoldItalic'),
local('TPHero-SemiBoldItalic'),
url(./fonts/TPHero-SemiBoldItalic.otf) format('otf');
} But there is no effect when I try to use it like: .p {
font-family: 'TPHero-Bold';
color: #333;
text-align: center;
} Do you have any idea about where it could come from ? |
|
Thank you so much. |
Is that additional webpack config section required @unknown075 ? |
I have added the TPHero font in
public
folder and@font-face
(refer to this old commit) but it does not seem to work.Could you please help?
The text was updated successfully, but these errors were encountered: