Replies: 5 comments 7 replies
-
Maybe to set font-family on some tag? html {
font-family: …
} |
Beta Was this translation helpful? Give feedback.
-
For those who want to use custom font in Nextra, now you can use Here is how to setup: Create import { Inter } from "@next/font/google";
const inter = Inter({ subsets: ["latin"] });
export default function MyApp({ Component, pageProps }) {
return (
<main className={inter.className}>
<Component {...pageProps} />
</main>
);
} Replace Restart your dev server. done. |
Beta Was this translation helpful? Give feedback.
-
Changing I instead opted to add '@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap');' to my globals.css file, and set html to use the font-family: Inter to get it to work. |
Beta Was this translation helpful? Give feedback.
-
I think changing
The reason you have refactored the file is to avoid this error when we add the
So why not make a React component for it: // components/Main.tsx
import { Inter } from "@next/font/google";
const inter = Inter({ subsets: ["latin"] });
export default function Main({ children }) {
return <main className={inter.className}>{children}</main>;
} And use it in import Main from "@/components/Main";
export default function Nextra({ Component, pageProps }) {
return (
<Main>
<Component {...pageProps} />
</Main>
);
} |
Beta Was this translation helpful? Give feedback.
-
Alternative solution via applying the font in the head. This avoids having a duplicate // fonts.ts
import { Inter } from 'next/font/google';
export const inter = Inter({ subsets: ['latin'] }); // pages/_app.mdx
import { inter } from '../fonts';
export default function Nextra({ Component, pageProps }) {
return (
<>
<style jsx global>{`
:root {
--font-inter: ${inter.style.fontFamily};
}
`}</style>
<Component {...pageProps} />
</>
);
} Use with tailwind: // tailwind.config.js
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ['var(--font-inter)', ...],
},
},
},
}; Use with css file: /* styles.css */
html {
font-family: var(--font-inter);
} The same can be done for local fonts and may be a workaround for vercel/geist-font#59. // fonts.ts
import localFont from 'next/font/local';
export const geist = localFont({
src: './fonts/GeistVF.woff2', //font file located in fonts folder created at root
weight: '100 900',
display: 'swap',
}); Follow the same process as above by importing |
Beta Was this translation helpful? Give feedback.
-
I want to use custom font.
I'm planning to use Google Fonts (this).
I set
theme.config.js
like this.And I add
fonts.css
like this.To deal it every pages, I changed
_app.js
But, it still doesn't work.
What should I do?
P.S.
This discussion was written in Oct 13, 2021 (maybe outdated).
What I did might be legacy steps.
Anyway, I'm using latest Nextra.
package.json
Beta Was this translation helpful? Give feedback.
All reactions