01
시작하기
CDN으로 설치
CDN 스크립트는 Tailwind로 프로토타이핑하는 가장 빠른 방법입니다. 마크업을 스캔해 런타임에 유틸리티를 생성합니다. 운영 환경에서는 사용하지 않는 클래스를 제거하고 작은 CSS 번들을 배포하려면 PostCSS나 CLI 빌드를 권장합니다.
tailwind
<!-- Quick start: drop this in <head> -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Tailwind scans class names in your HTML and generates styles on the fly -->
<h1 class="text-3xl font-bold text-blue-600">Hello Tailwind</h1>프로젝트 설정(CLI)
content 배열이 핵심입니다. Tailwind는 그 파일들에서 발견한 클래스만 생성합니다(트 리 셰이킹). 경로를 빠뜨리는 것이 '내 클래스가 없다' 버그의 1위 원인입니다. 개발 중에는 --watch를 사용하세요.
tailwind
# Install Tailwind as a project dependency
npm install -D tailwindcss
npx tailwindcss init
# tailwind.config.js — tell Tailwind where your templates live
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js,jsx,ts,tsx}"],
theme: { extend: {} },
plugins: [],
};
# Build CSS
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch입력 CSS 지시문
@tailwind 지시문은 Tailwind의 세 레이어를 순서대로 주입합니다: base(리셋), components, utilities. @layer는 사용자 CSS를 올바른 캐스케이드 레이어에 추가합니다. @apply는 유틸리티 스타일을 사용자 정의 규칙에 인라인합니다.
tailwind
/* src/input.css — the three layers Tailwind uses */
@tailwind base; /* normalize/reset + base element styles */
@tailwind components; /* component classes you register */
@tailwind utilities; /* the utility classes themselves */
/* Add custom CSS after the directives */
@layer base {
h1 { @apply text-2xl; }
}유틸리티 우선 사고 모델
Tailwind의 철학: 의미 있는 클래스 이름을 새로 만들기보다 작은 단일 목적 유틸리티 클래스를 조합해 UI를 만듭니다. CSS를 평탄하게 유지하고 죽은 코드를 피하며 공유 간격/색상 스케일로 디자인을 일관되게 만듭니다.
tailwind