0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsでGoogleFontsを適用した手順

0
Last updated at Posted at 2026-02-01
  1. Googlefontsで使いたいフォントを決める
  2. Get font ボタンを押す
  3. <>Get Embed Codeを押す

手順

`layout.tsx'にimportを追加する

import { DotGothic16 } from "next/font/google";

定義を追加する

export const dotgothic = DotGothic16({
  subsets: ["latin"],
  weight: "400",
  variable: "--font-dotgothic",
});

定義したフォントを body の className に追加

デフォルトのテンプレートから作成だと、二つ記述があるのでそこに追加する形に今回はしました。
before

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      >
        {children}
      </body>
    </html>
  );
}

after

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body
        className={`${geistSans.variable} ${geistMono.variable} ${dotgothic.variable} antialiased`}      
      >
        {children}
      </body>
    </html>
  );
}

CSSにクラスを定義する

.dotgothic {
  font-family: var(--font-dotgothic), system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans JP", sans-serif;
  font-weight: 400;
}

使い方

<span className="dotgothic">ほげほげ</span>

DotGothic16はこんな感じ

image.png

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?