1 | initial version |
To load custom fonts in Next.js, you can follow these steps:
Place your font files (e.g. .woff, .woff2) into the 'public' directory of your Next.js project.
Create a CSS file (e.g. 'fonts.css') and import your font files using @font-face. For example:
@font-face { font-family: 'MyFont'; src: url('/fonts/myfont.woff2') format('woff2'), url('/fonts/myfont.woff') format('woff'); }
import '../styles/fonts.css';
h1 { font-family: 'MyFont', sans-serif; }
Note: If you are using a CSS-in-JS library like styled-components, you can still follow the same steps above, but modify step 2 to include the @font-face declaration in your styled-component.