Tailwind CSS 테마 설정 (Theming)
Tailwind v4 출시 이후 테마 커스터마이즈는 tailwind.config.js 파일에서 네이티브 CSS 테마 변수로 이동했어요. 이 방식은 색상·폰트·섀도우·스페이싱 등을 훨씬 자연스럽게 커스터마이즈할 수 있는 장점이 있습니다. Flowbite 디자인 시스템의 새로운 커스텀 변수를 활용해 프로젝트를 더 쉽게 커스터마이즈해 보세요.
출처: 문서
본문
시작하기 (Getting started)
Flowbite v4에서 커스텀 테마를 도입하면서 이제 input.css 파일에서 원하는 테마 중 하나를 import 할 수 있어요.
/* 원하는 테마 중 하나를 선택하세요 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
@import "flowbite/src/themes/default";
/* MINIMAL 테마
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap');
@import "flowbite/src/themes/minimal";
*/
/* ENTERPRISE 테마
@import url('https://fonts.googleapis.com/css2?family=Shantell+Sans:ital,wght@0,300..800;1,300..800&display=swap');
@import "flowbite/src/themes/enterprise";
*/
/* PLAYFUL 테마
@import url('https://fonts.googleapis.com/css2?family=Google+Sans+Code:ital,wght@0,300..800;1,300..800&display=swap');
@import "flowbite/src/themes/playful";
*/
/* MONO 테마
@import "flowbite/src/themes/mono";
*/
다음은 커스텀 색상·폰트 집합을 설정한 수정된 CSS 파일의 예시예요.
/* input.css 파일 */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
@theme {
--color-fg-brand-subtle: var(--color-blue-200);
--color-fg-brand: var(--color-blue-700);
--color-fg-brand-strong: var(--color-blue-900);
--color-brand-softer: var(--color-blue-50);
--color-brand-soft: var(--color-blue-100);
--color-brand: var(--color-blue-700);
--color-brand-medium: var(--color-blue-200);
--color-brand-strong: var(--color-blue-800);
--font-sans: 'Inter', 'ui-sans-serif', 'system-ui', '-apple-system', 'system-ui', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'Noto Sans', 'sans-serif', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-body: 'Inter', 'ui-sans-serif', 'system-ui', '-apple-system', 'system-ui', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'Noto Sans', 'sans-serif', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-mono: 'ui-monospace', 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', 'Liberation Mono', 'Courier New', 'monospace';
}
이 변수들은 이제 brand라는 새 색상 팔레트를 만들고, 기본으로 Inter 폰트를 사용하는 폰트 집합을 제공합니다.
/* choose one of the following */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
@import "flowbite/src/themes/default";
/* MINIMAL THEME
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap');
@import "flowbite/src/themes/minimal";
*/
/* ENTERPRISE THEME
@import url('https://fonts.googleapis.com/css2?family=Shantell+Sans:ital,wght@0,300..800;1,300..800&display=swap');
@import "flowbite/src/themes/enterprise";
*/
/* PLAYFUL THEME
@import url('https://fonts.googleapis.com/css2?family=Google+Sans+Code:ital,wght@0,300..800;1,300..800&display=swap');
@import "flowbite/src/themes/playful";
*/
/* MONO THEME
@import "flowbite/src/themes/mono";
*/
/* input.css file */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
@theme {
--color-fg-brand-subtle: var(--color-blue-200);
--color-fg-brand: var(--color-blue-700);
--color-fg-brand-strong: var(--color-blue-900);
--color-brand-softer: var(--color-blue-50);
--color-brand-soft: var(--color-blue-100);
--color-brand: var(--color-blue-700);
--color-brand-medium: var(--color-blue-200);
--color-brand-strong: var(--color-blue-800);
--font-sans: 'Inter', 'ui-sans-serif', 'system-ui', '-apple-system', 'system-ui', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'Noto Sans', 'sans-serif', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-body: 'Inter', 'ui-sans-serif', 'system-ui', '-apple-system', 'system-ui', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'Noto Sans', 'sans-serif', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-mono: 'ui-monospace', 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', 'Liberation Mono', 'Courier New', 'monospace';
}
Flowbite 플러그인 (Flowbite Plugin)
Flowbite를 설치한 뒤에는 메인 CSS 파일에 Flowbite 플러그인도 함께 import 해야 해요.
/* input.css 파일 */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
이렇게 하면 폼, 체크박스, 툴팁, 차트, datatables의 의사(pseudo) 스타일이 적용됩니다.
/* input.css file */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
테마 옵션 (Theme options)
Tailwind CSS에서 테마가 동작하는 방식을 이해하는 가장 좋은 예는, 새 색상 변수를 추가하면 그것이 모든 텍스트·배경·테두리 관련 색상에서 사용 가능해지는 것이에요. 기본적으로 새 색상은 사용 가능한 모든 유틸리티 클래스로 전파됩니다. 스페이싱, 컨테이너, 폰트, 사이징 등 기본 유틸리티 클래스를 커스터마이즈할 수 있는 변수 네임스페이스도 더 많이 있습니다.
색상 (Colors)
--color-{name} 변수 네임스페이스로 색상을 업데이트하거나 추가할 수 있어요.
@theme {
--color-fg-brand-subtle: var(--color-blue-200);
--color-fg-brand: var(--color-blue-700);
--color-fg-brand-strong: var(--color-blue-900);
--color-brand-softer: var(--color-blue-50);
--color-brand-soft: var(--color-blue-100);
--color-brand: var(--color-blue-700);
--color-brand-medium: var(--color-blue-200);
--color-brand-strong: var(--color-blue-800);
}
이제 text-fg-brand, bg-brand 같은 유틸리티 클래스가 커스텀 브랜드 색상을 표시합니다.
폰트 (Fonts)
CSS 파일에서 --font-body 변수를 업데이트해 나만의 폰트를 추가할 수 있어요. 문서의 태그에 antialiased를 적용해 폰트 부드러움(smoothing)을 활성화해야 합니다.
스페이싱 (Spacing)
spacing-{name} 변수 네임스페이스로 너비·높이·패딩·마진 등을 설정하는 유틸리티 클래스의 스페이싱 값을 지정할 수 있어요.
@theme {
--spacing-custom: 10px;
}
브레이크포인트 (Breakpoints)
메인 CSS 파일에서 --breakpoint-{size} 변수 네임스페이스를 사용해 반응형 모바일 우선 유틸리티 클래스가 적용되는 브레이크포인트를 커스터마이즈할 수 있어요.
/* input.css file */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
@theme {
--color-fg-brand-subtle: var(--color-blue-200);
--color-fg-brand: var(--color-blue-700);
--color-fg-brand-strong: var(--color-blue-900);
--color-brand-softer: var(--color-blue-50);
--color-brand-soft: var(--color-blue-100);
--color-brand: var(--color-blue-700);
--color-brand-medium: var(--color-blue-200);
--color-brand-strong: var(--color-blue-800);
}
/* input.css file */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
@theme {
--font-sans: 'Inter', 'ui-sans-serif', 'system-ui', '-apple-system', 'system-ui', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'Noto Sans', 'sans-serif', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-body: 'Inter', 'ui-sans-serif', 'system-ui', '-apple-system', 'system-ui', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'Noto Sans', 'sans-serif', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-mono: 'ui-monospace', 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', 'Liberation Mono', 'Courier New', 'monospace';
}
/* input.css file */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
@theme {
--spacing-custom: 10px;
}
/* input.css file */
@import "tailwindcss";
@plugin "flowbite/plugin";
@source "../node_modules/flowbite";
@theme {
--breakpoint-xs: 30rem;
--breakpoint-2xl: 100rem;
--breakpoint-3xl: 120rem;
}
참고 (Reference)
구성 가능한 모든 변수 네임스페이스는 Tailwind CSS 공식 문서에서 확인할 수 있어요. 다크 모드, 색상 관련 문서와 함께 참고하세요.