Next.js | font 설정

2024. 4. 12. 18:27·Next.js

Next.js 에서 font 설정하기

font 설정하는 방법에는 2가지가 있다.
1. 구글 폰트 사용하기 
(링크 : https://nextjs.org/docs/pages/building-your-application/optimizing/fonts)
2. Local Font

 

 ✔️ Local Font

사용하려는 폰트가 prentandard인데 구글 폰트에 없어서 로컬 폰트로 적용하는 방법을 선택할 수 밖에 없었다.

나는 public 폴더 안에 fonts 폴더를 만들어서 ttf 파일들을 넣어주었다.

 

그 다음 fonts.css 파일을 생성하여 폰트를 설정해준다.

@font-face {
    font-family: 'Pretendard';
    font-weight: 100;
    font-style: normal;
    src: url('../public/fonts/Pretendard-Thin.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 200;
    font-style: normal;
    src: url('../public/fonts/Pretendard-ExtraLight.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 300;
    font-style: normal;
    src: url('../public/fonts/Pretendard-Light.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 400;
    font-style: normal;
    src: url('../public/fonts/Pretendard-Regular.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 500;
    font-style: normal;
    src: url('../public/fonts/Pretendard-Medium.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 600;
    font-style: normal;
    src: url('../public/fonts/Pretendard-SemiBold.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 700;
    font-style: normal;
    src: url('../public/fonts/Pretendard-Bold.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 800;
    font-style: normal;
    src: url('../public/fonts/Pretendard-ExtraBold.ttf') format('truetype');
}

@font-face {
    font-family: 'Pretendard';
    font-weight: 900;
    font-style: normal;
    src: url('../public/fonts/Pretendard-Black.ttf') format('truetype');
}

body {
    font-family: 'Pretendard';
    font-weight: 400;
}

 

그리고 _app.js 파일에서 

import '../styles/fonts.css'

 

임포트 시켜주면 된다.

 

참고 : https://velog.io/@minju1009/Nextjs%EC%97%90-%ED%8F%B0%ED%8A%B8-%EC%A0%81%EC%9A%A9%ED%95%98%EB%A0%A4%EB%A9%B4

'Next.js' 카테고리의 다른 글

router 와 window.location.href 차이  (1) 2025.04.28
별칭 경로 설정  (0) 2024.07.12
[Next.js 당근마켓] Tailwind CSS 란?  (3) 2024.07.09
[Next.js 당근마켓] 프로젝트 생성 및 실행  (0) 2024.07.09
'Next.js' 카테고리의 다른 글
  • router 와 window.location.href 차이
  • 별칭 경로 설정
  • [Next.js 당근마켓] Tailwind CSS 란?
  • [Next.js 당근마켓] 프로젝트 생성 및 실행
개발 공부
개발 공부
  • 개발 공부
    개발 공부
    개발 공부
  • 전체
    오늘
    어제
    • 전체보기 (163)
      • 프로젝트 (1)
      • JavaScript (46)
      • Node.js (3)
      • Next.js (5)
      • React (17)
      • NoSQL (0)
      • HTML,CSS (3)
      • CS (6)
      • Java (35)
      • Spring (6)
        • Spring의 정석 (1)
      • Spring boot (1)
      • MySQL (1)
      • 리눅스 (16)
      • JSP (9)
      • AWS (0)
      • git (2)
      • 알고리즘 (1)
      • ect (7)
      • Project (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Java
    Java의 정석
    오블완
    자바의 정석
    자바
    티스토리챌린지
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
개발 공부
Next.js | font 설정
상단으로

티스토리툴바