Search code examples
reactjsfontsnext.jstailwind-cssgoogle-fonts

NextJS - Google font is not loading or displaying on the website


Followed the documentation and added a _document.js file with the provided code:

import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx)
    return { ...initialProps }
  }

  render() {
    return (
      <Html>
        <Head>
          <link href="https://fonts.googleapis.com/css2?family=Almarai:wght@300;400;700&display=swap" rel="stylesheet" />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument

When I use my chrome extension font checker and verify in the inspector, it states that it using the defaults fonts. Any idea how I can get this to work? Might there be some interference with the fact that I'm using tailwindcss?


Solution

  • in globals.css

    /* Google Font */
    @import url('https://fonts.googleapis.com/css2?family=Kurale&display=swap');
    
    /* From Public Directory */
    @font-face {
      font-family: 'Kurale';
      src: url('/fonts/Kurale.ttf');
      font-style: medium;
      font-weight: normal;
      font-display: swap;
    }