DEV Community

Cover image for Font Optimization
Gereltuya Munkhzaya
Gereltuya Munkhzaya

Posted on • Updated on

Font Optimization

Google Fonts

Automatically self-host any Google Font. Fonts are included in the deployment and served from the same domain as your deployment. No requests are sent to Google by the browser.

Get started by importing the font you would like to use from next/font/google as a function. We recommend using variable fonts for the best performance and flexibility.

To use the font in all your pages, add it to _app.js file under /pages as shown below:

Apply the font in


You can also use the font without a wrapper and className by injecting it inside the as follows:
import { Inter } from 'next/font/google'

const inter = Inter({ subsets: ['latin'] })

export default function MyApp({ Component, pageProps }) {
  return (
    <>
      <style jsx global>{`
        html {
          font-family: ${inter.style.fontFamily};
        }
      `}</style>
      <Component {...pageProps} />
    </>
  )
}
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
mezieb profile image
Okoro chimezie bright

Well done!!!,we are glad to have you on board.