79491019

Date: 2025-03-07 01:06:17
Score: 1
Natty:
Report link

I looked closer at the docs and this line caught my eye:

If you're loading a font from a service like Google Fonts, make sure to put the @import at the very top of your CSS file:

I inspected the compiled CSS in the browser, and turns out the @import url line was not at the top of the compiled CSS. There were some @font-face lines before that.

screenshot showing @import line being preceded by other CSS code

Geist is of course the default font that comes with every Next.js install. I determined that to load a custom font, I could either load all of my Google fonts using next/font/google or the Tailwind way (i.e. don't mix methods). I chose the latter and the font now loads as intended.

Specifically I removed these lines to get the @import in my CSS working:

modified   src/app/layout.tsx

@@ -1,17 +1,6 @@
 import type { Metadata } from "next";
-import { Geist, Geist_Mono } from "next/font/google";
 import "./globals.css";

-const geistSans = Geist({
-  variable: "--font-geist-sans",
-  subsets: ["latin"],
-});
-
-const geistMono = Geist_Mono({
-  variable: "--font-geist-mono",
-  subsets: ["latin"],
-});
-
 export const metadata: Metadata = {
   title: "Create Next App",
   description: "Generated by create next app",
@@ -24,11 +13,7 @@
 }>) {
   return (
     <html lang="en">
-      <body
-        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
-      >
-        {children}
-      </body>
+      <body className={`antialiased`}>{children}</body>
     </html>
   );
 }
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @import
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Screensavers