I am building an app with the next JS using [theme-UI][1]. But in my project, I have to use local fonts or custom fonts. But I have no idea how can I do that. Here is my theming
const theme = {
fonts: {
body: 'CircularBlack',
heading: 'CircularBlack',
monospace: 'Menlo, monospace',
},
Here is theming-
export default {
fonts: {
body: "fufu", //text
heading: "fufu", //boxShape
monospace: "fufu", //header
}
styles: {
root: {
p: 0,
m: 0,
background: 'primary',
cursor: 'default',
position: 'relative',
overflowX: "hidden",
fontFamily: "body",
}
},
}
Here I use fonts name in fonts object and I call it into root element. [1]: https://theme-ui.com/
Get the
.woff
and.woff2
files for the fonts you want to integrate from the web (e.g. https://www.cufonfonts.com/font/menlo)Put these files into a folder like
my-next-app/public/fonts/menlo.woff2
- anything in thepublic
folder inside a next js app will be statically served - just make sure to copy these files too onto your webserver if your hosting it manually.Afterwards you need to integrate the fonts in a way - with basic CSS like:
I don't know theme-ui so i cannot say where these
@font-face
definitions should be integrated.. We do it in a global-styles.css which we just integrate with a custompages/_app.tsx
file (https://nextjs.org/docs/advanced-features/custom-app)Now you should be fine to use the font anywhere in your application, also in your theme-ui as you already have written.