LoginSignup
15
2

More than 1 year has passed since last update.

React プロジェクトで Google Fonts を使う

Posted at

React プロジェクトで Google Fonts を使う

おしゃれなフォントを見つけたので適用方法をメモ書き

1. importコード生成

まずは、Google Fontsでいい感じのFontを見つけます

見つけたら、+ Select this styleをクリックします

google_fonts_01.png

すると、右側にナビゲーションが出てきます
(出てこない場合は画面上のメニュー内のアイコンをクリック)

google_fonts_02.png

ここでいったん置いておく

2. React App で読み込む

React側でCSSを適用させます

2-1. style.css を作成

style.cssを作成し、ナビゲーションメニューに出てきた
@importの部分をコピペします

また、bodyタグのfont-familyをGoogleFontsのFont名にします

style.css
@import url('https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic&display=swap');

body {
  font-family: 'Zen Maru Gothic', sans-serif;
}

2-2. cssを読み込む

作成したcssを、フォント適用させたいコンポーネントでimportします

App.tsx
import './style.css';

function App () {
  // 
}

完了!

15
2
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
15
2