본문 바로가기
프로그래밍/web

nextjs에 google font 적용하기

by ® 2021. 11. 22.
반응형

1. GOOGLE FONT 사이트에 가서 원하는 폰트를 찾는다.

 

Google Fonts

Making the web more beautiful, fast, and open through great typography

fonts.google.com

 

2. pages/index.js <head> 태그 내에 아래의 <link> 태그를 입력한다.

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=적용할 폰트 이름" rel="stylesheet">

 

예를 들어, Noto Sans KR의 경우 아래와 같다.

<Head>
  ...
  <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap" rel="stylesheet" />
</Head>

 

3. css에서 font-family에 해당 폰트를 적용한다.

.css-selector {
	font-family: '폰트 이름', serif;
}

 

예를 들어, mui theme에 global에게 적용할 경우 아래와 같다.

let theme = createMuiTheme({
  typography: {
    fontFamily: `"Noto Sans CJK KR", sans-serif`,
  },
  palette: {
    primary: {
      main: "#4A97FF"
    },
    secondary: {
      main: "#343A40"
    }
  },
})
반응형

댓글