search

New

6/recent/ticker-posts

Add google font family with nextjs


Add CSS to a specific website page.

Apply CSS in next.js with the local asset; use CSS font-face property to add CSS. Inside font-face CSS property, you pass folder path with exact extension. Now your font is ready to use inside your next js.

@font-face { 

font-family: 'OpenSans';src: url('../asset/OpenSans/OpenSans-Light.ttf'); 

src: url('../asset/OpenSans/OpenSans-Medium.ttf'); 

font-weight: 400;font-style: normal; 

}

Use Font in CSS

h1, h2,h3 {font-family: OpenSans, sans-serif;font-weight: 400;}

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

export default function Document() {
return (
<Html>
<Head>
<link rel="preconnect" href="https://fonts.googleapis.com" /> 

        <link rel="preconnect" href="https://fonts.gstatic.com" />

         <link href="https://fonts.googleapis.com/css2?family=Anek+Malayalam:wght@200;300&family=Montserrat:wght@300;400&display=swap" rel="stylesheet" />

         </Head>

         <body>
<Main />
<NextScript />
</body>
</Html>
)
}

Use the CSS import method.

 


Post a Comment

0 Comments

Contact Form

Name

Email *

Message *

Random Products

Learning English