How to import and use local fonts
See original GitHub issueI 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?
// webpack
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
loader: 'file-loader',
query: {
name: isDebug ? '[path][name].[ext]?[hash:8]' : '[hash:8].[ext]',
},
},
// in variable.css
@font-face {
font-family: 'TPHero';
font-style: normal;
font-weight: normal;
src:
url('../../../public/fonts/TPHero/TPHero-Bold.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-BoldItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-ExtraBold.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-ExtraBoldItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-Hairline.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-HairlineItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-Light.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-LightItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-Medium.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-MediumItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-Regular.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-RegularItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-SemiBold.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-SemiBoldItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-Super.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-Thin.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-ThinItalic.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-UltraLight.otf') format('otf'),
url('../../../public/fonts/TPHero/TPHero-UltraLightItalic.otf') format('otf');
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
To use local font in HTML using font face - Stack Overflow
To use local font in HTML using font face · Try to open the developer console (F12), what does it say? – Bálint...
Read more >How To Load and Use Custom Fonts with CSS | DigitalOcean
Using local fonts relieves the browser of downloading and processing ... To do that, select the <link> option instead of the @import option ......
Read more >The Easy Way to Add Fonts to Your Website (Including ...
How to add custom fonts to your website using @font-face · Step 1: Download the font · Step 2: Create a WebFont Kit...
Read more >How to use @font-face in CSS
Google Fonts offers this as a way to use their fonts. The following is an example of using @import to load the Open...
Read more >Access local fonts on your computer - Figma Help Center
This is a secure background service that allows Figma to access any fonts on your computer and make them available in the font...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
.otf
isformat('opentype')
, demoYou should not put to variables.css anything except variables, otherwise the code will be duplicated multiple times - depends on how many
@import
s of thevariables.css
file do you have.The best place for custom fonts is your top level react component (
src/components/Layout/Layout.css
in RSK).Then you need to define
@font-face
for each font separately. For examplelight
,italic
,bold
etc. are different fonts. Also it is not recommended to import more than 2-3 fonts per page - it it too heavy.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
url(./fonts/font-name.ext)
, but if you want save font-file name on production, put them topublic/fonts/font-name.ext
folder and use absolute path in cssurl(/fonts/font-name.ext)
.Example: