I am trying to use Google Fonts on a Nextjs project with the newest version 13 and I can’t import Google Fonts (i.e. Poppins) correctly.
In the past I just added the link tags to the _document.js
or _app.js
file and that was it.
I am trying it this way without success:
<Head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet"></link>
</Head>
In the past, an alternative was to import the Google fonts on the global CSS stylesheet with @import but this method doesn’t work either:
@import url("https://fonts.googleapis.com/css?family=Poppins:300,400,700");
Please let me know how can I do it on Next version 13 and up
2
Answers
To use Google fonts on a Next 13+ project you can do it this way:
app/layout.js
And then in any CSS file you can use that font this way
You should use
next/font
Refer to this: https://nextjs.org/docs/app/api-reference/components/font