🎨 Tailwind CSS v4μ—μ„œ tailwind.config 없이 Custom Color & Font μ μš©ν•˜λŠ” 방법

neomΒ·2025λ…„ 5μ›” 19일
post-thumbnail

πŸ“Œ λ°°κ²½

Tailwind CSS v4λŠ” 이전 버전과 달리 tailwind.config.js 파일 없이도,
CSS 파일 μ•ˆμ—μ„œ 색상, 폰트, μœ ν‹Έλ¦¬ν‹° 등을 직접 μ •μ˜ν•  수 μžˆλ„λ‘ κ°œνŽΈλ˜μ—ˆμŠ΅λ‹ˆλ‹€.

ν•˜μ§€λ§Œ μ•„μ§κΉŒμ§€ λ§Žμ€ λΈ”λ‘œκ·Έλ‚˜ νŠœν† λ¦¬μ–Ό, 심지어 ChatGPT쑰차도 v3 κΈ°μ€€μ˜ μ˜ˆμ‹œκ°€ λŒ€λΆ€λΆ„μ΄λΌ
v4 방식이 ν•„μš”ν–ˆλ˜ 저에겐 큰 도움이 λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.
κ·Έλž˜μ„œ μ œκ°€ ν”„λ‘œμ νŠΈλ₯Ό ν•˜λ©° 직접 μ μš©ν•œ κ²½ν—˜μ„ λ°”νƒ•μœΌλ‘œ, μ‹€μ „μ—μ„œ λ°”λ‘œ μ“Έ 수 μžˆλŠ” 방법을 μ •λ¦¬ν•΄λ΄€μŠ΅λ‹ˆλ‹€!!



🧩 1. TailwindCSS import

κΈ°μ‘΄ v3μ—μ„œλŠ” μ•„λž˜μ™€ 같이 각각의 κ³„μΈ΅λ³„λ‘œ λ”°λ‘œ λΆˆλŸ¬μ™€μ•Ό ν–ˆμŠ΅λ‹ˆλ‹€.

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

ν•˜μ§€λ§Œ Tailwind v4λΆ€ν„°λŠ” ν•œ μ€„λ‘œ importκ°€ κ°€λŠ₯ν•©λ‹ˆλ‹€.

@import "tailwindcss";

μ €λŠ” index.css (λ˜λŠ” global.css) μ΅œμƒλ‹¨μ— μ΄λ ‡κ²Œ μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€.



🎨 2. Custom Color μ„€μ •

λŒ€λΆ€λΆ„μ˜ ν”„λ‘œμ νŠΈμ—μ„œλŠ” λ””μžμ΄λ„ˆκ°€ μ œκ³΅ν•œ λ””μžμΈ μ‹œμŠ€ν…œ 컬러λ₯Ό μ‚¬μš©ν•˜κ²Œ 되죠.
Tailwindμ—μ„œ μ œκ³΅ν•˜λŠ” κΈ°λ³Έ 색상이 μ•„λ‹Œ 경우, @theme μ•ˆμ— μ›ν•˜λŠ” 색상 λ³€μˆ˜λ₯Ό 등둝해 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@theme {
  --color-red: #FD7563;
  --color-green-100: #BBEFDA;
  --color-green-200: #52D38A;
  --color-green-300: #44D496;
}

κΈ°λ³Έ 색상 값을 λΉ„μ›Œμ„œ μ΄ˆκΈ°ν™”ν•˜κ³  μ‹Άλ‹€λ©΄ μ•„λž˜μ™€ 같이 μž‘μ„±ν•©λ‹ˆλ‹€.

@theme {
  --color-*: initial;
  ...
}

βœ… 적용 μ˜ˆμ‹œ

μ •μ˜ν•œ 색상은 클래슀λͺ…μœΌλ‘œ λ°”λ‘œ μ‚¬μš© κ°€λŠ₯ν•©λ‹ˆλ‹€.

<p className={`text-red`}> λ§ˆμ΄νŽ˜μ΄μ§€ </p>

πŸ‘‰ --color-red β†’ text-red
Tailwind v4λŠ” λ³€μˆ˜ 기반 컬러λ₯Ό μžλ™μœΌλ‘œ text-, bg- λ“±μ˜ 클래슀둜 λ³€ν™˜ν•΄μ€λ‹ˆλ‹€.



πŸ–‹οΈ 3. Custom Font μ„€μ •

ν°νŠΈλŠ” url둜 κ°€μ Έμ˜€κ±°λ‚˜ 직접 폰트 νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œ λ°›μ•„ src/assets/font 폴더 μ•ˆμ— 폰트 νŒŒμΌλ“€μ„ λ„£λŠ” 방법이 μžˆλŠ”λ° μ €λŠ” ν›„μžλ‘œ κ΅¬ν˜„ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

1) 폰트 파일 μ€€λΉ„

μ €λŠ” Pretendard의 Regular, Medium, SemiBold, Bold 버전을 μ‚¬μš©ν–ˆκΈ° λ•Œλ¬Έμ— .ttf 파일 4개λ₯Ό /src/assets/fonts 폴더에 λ„£μ—ˆμŠ΅λ‹ˆλ‹€.

πŸ’‘ 폰트 포맷은 μ—¬λŸ¬ κ°€μ§€κ°€ 있으며, 웹에 κ°€μž₯ μ ν•©ν•œ 것은 woff2μž…λ‹ˆλ‹€. λ‹€λ§Œ 개발 μ΄ˆκΈ°μ—λŠ” ttfλ§ŒμœΌλ‘œλ„ μΆ©λΆ„νžˆ 적용 κ°€λŠ₯ν•©λ‹ˆλ‹€.

πŸ”€ μ£Όμš” 폰트 포맷 μ’…λ₯˜

ν˜•μ‹ ν™•μž₯자 format() κ°’ μ„€λͺ…
TrueType .ttf 'truetype' 였래된 ν‘œμ€€, λŒ€λΆ€λΆ„μ˜ λΈŒλΌμš°μ € 지원
OpenType .otf 'opentype' 더 μ •κ΅ν•œ κΈ€κΌ΄ κΈ°λŠ₯ 지원
WOFF .woff 'woff' μ›Ή μ „μš©μœΌλ‘œ μ••μΆ•λœ 포맷, 많이 μ‚¬μš©λ¨
WOFF2 .woff2 'woff2' WOFF보닀 더 높은 μ••μΆ•λ₯ , μ΅œμ‹  λΈŒλΌμš°μ €μš©
Embedded OpenType .eot 'embedded-opentype' 주둜 κ΅¬ν˜• IE용
SVG Fonts .svg 'svg' iOS μ˜›λ‚  λ²„μ „μ—μ„œλ§Œ μ‚¬μš©, ν˜„μž¬λŠ” 거의 μ•ˆ 씀


2) 폰트 등둝

이제 CSS에 @font-faceλ₯Ό 톡해 직접 폰트λ₯Ό λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.
μ €λŠ” μ•„λž˜μ²˜λŸΌ index.css에 μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€.

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

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

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

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

βœ… @font-face 속성 μ„€λͺ… 정리

속성 μ„€λͺ…
font-family 폰트의 이름을 μ •μ˜ν•˜λŠ” λΆ€λΆ„μž…λ‹ˆλ‹€. Tailwindλ‚˜ CSSμ—μ„œ 이 μ΄λ¦„μœΌλ‘œ 폰트λ₯Ό μ°Έμ‘°ν•˜κ²Œ λ©λ‹ˆλ‹€. 예: 'Pretendard'
font-style 폰트의 μŠ€νƒ€μΌμ„ μ§€μ •ν•©λ‹ˆλ‹€. normal은 κΈ°λ³Έ, italic은 κΈ°μšΈμ–΄μ§„ μ΄νƒ€λ¦­μ²΄μž…λ‹ˆλ‹€.
font-weight 폰트의 λ‘κ»˜λ₯Ό μ§€μ •ν•©λ‹ˆλ‹€. 보톡 400(Regular), 500(Medium), 600(SemiBold), 700(Bold) 등이 μ‚¬μš©λ©λ‹ˆλ‹€.
src 폰트 파일의 κ²½λ‘œμ™€ ν˜•μ‹μ„ μ§€μ •ν•©λ‹ˆλ‹€.
format() 폰트 파일의 ν˜•μ‹μ„ λͺ…μ‹œν•©λ‹ˆλ‹€. λΈŒλΌμš°μ € μ΅œμ ν™”λ₯Ό μœ„ν•΄ μž‘μ„±ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. 예: 'truetype', 'woff', 'woff2' λ“±

πŸ“Œ μ°Έκ³ : format()은 μƒλž΅ κ°€λŠ₯ν•˜μ§€λ§Œ, λͺ…μ‹œν•΄μ£ΌλŠ” 것이 λΈŒλΌμš°μ € ν˜Έν™˜μ„±κ³Ό μ„±λŠ₯에 더 μ’‹μŠ΅λ‹ˆλ‹€.



3) 폰트λ₯Ό μœ ν‹Έλ¦¬ν‹° 클래슀둜 등둝

Tailwind v4μ—μ„œλŠ” @layer utilities μ•ˆμ— μ»€μŠ€ν…€ 클래슀λ₯Ό μ •μ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

@layer utilities {
  .font-head02-bold-20 {
    font-family: 'PretendardBold', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    line-height: normal;
    letter-spacing: -0.6px;
  }

  .font-body01-regular-14 {
    font-family: 'PretendardRegular', sans-serif;
    font-size: 1.4rem;
    font-weight: 400;
    letter-spacing: -0.6px;
    line-height: normal;
  }
}

βœ… 적용 μ˜ˆμ‹œ

<header className={`flex justify-between font-head02-bold-20 p-4`}>
    <p onClick={goMyPage} className={`text-red`}>
      λ§ˆμ΄νŽ˜μ΄μ§€
	</p>
	<p onClick={goLoginPage}>둜그인</p>
</header>


κ²°λ‘ 

Tailwind v4μ—μ„œλŠ” 더 이상 tailwind.config.js 없이도, CSS 파일만으둜 색상과 폰트λ₯Ό 자유둭게 μ»€μŠ€ν…€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이 방식은 λ””μžμ΄λ„ˆκ°€ μ œκ³΅ν•˜λŠ” μ‹œμŠ€ν…œ λ””μžμΈμ„ λΉ λ₯΄κ²Œ λ°˜μ˜ν•˜κ±°λ‚˜,ν”„λ‘ νŠΈ λ‹¨μ—μ„œ μ†μ‰½κ²Œ ν…Œλ§ˆ 변경이 ν•„μš”ν•  λ•Œλ„ 맀우 μœ μš©ν•©λ‹ˆλ‹€.😊

✍️ μ •λ¦¬ν•˜λ©΄

ν•­λͺ© 적용 방법
Tailwind 뢈러였기 @import "tailwindcss" ν•œ 쀄
색상 μ„€μ • @theme { --color-* }둜 μ„€μ •, text-*, bg-* 클래슀 μ‚¬μš© κ°€λŠ₯
폰트 뢈러였기 @font-face둜 직접 등둝 (.ttf, .woff λ“±)
폰트 μœ ν‹Έλ¦¬ν‹° @layer utilities μ•ˆμ— 클래슀 직접 μ •μ˜


tailwindcss colors 곡식 λ¬Έμ„œ
tailwindcss font 곡식 λ¬Έμ„œ

profile
ν–‰λ³΅ν•˜κ²Œ μ‚΄λž˜μ—¬

0개의 λŒ“κΈ€