본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Tailwind CSS용 daisyUI 테마

원문 보기 위키 갱신

daisyUI는 35개의 내장 테마를 제공해요. 몇 줄 설정으로 웹사이트 분위기를 통째로 바꾸고, 테마를 활성화·커스터마이징·관리하는 법을 알아볼게요.

출처: 문서

본문

daisyUI는 Tailwind CSS용 테마 35개를 기본 제공해요. 웹사이트의 분위기를 즉시 바꾸고, 색상 시스템을 처음부터 설계하는 수고를 덜어 주죠. 직접 커스텀 테마를 만들거나 내장 테마를 커스터마이징할 수도 있어요.

테마 관리는 CSS 파일의 @plugin "daisyui" 앞에 중괄호를 붙여서 해요.

app.css

  @import "tailwindcss";
- @plugin "daisyui";
+ @plugin "daisyui" {
+   themes: light --default, dark --prefersdark;
+ }
  • themes는 활성화할 테마 이름을 쉼표로 구분한 목록이에요.
  • 어떤 테마에 --default 플래그를 붙이면 기본 테마가 돼요.
  • 어떤 테마에 --prefersdark 플래그를 붙이면 다크 모드(prefers-color-scheme: dark)용 기본 테마가 돼요.

내장 테마 활성화

기본적으로 light와 dark 테마가 활성화돼 있어요. cupcake 테마를 활성화해 볼게요.

app.css

@import "tailwindcss";
@plugin "daisyui" {
  themes: light --default, dark --prefersdark, cupcake;
}

그리고 페이지에 cupcake 테마를 설정해요.

index.html

<html data-theme="cupcake"></html>

테마를 전환하고 선택한 테마를 local storage에 저장하려면 theme-change 같은 것을 쓰는 걸 추천해요.

테마 목록

직접 체험해 볼 수 있는 내장 테마들: light, dark, cupcake, bumblebee, emerald, corporate, synthwave, retro, cyberpunk, valentine, halloween, garden, forest, aqua, lofi, pastel, fantasy, wireframe, black, luxury, dracula, cmyk, autumn, business, acid, lemonade, night, coffee, winter, dim, nord, sunset, caramellatte, abyss, silk

모든 테마 활성화

themes를 all로 설정하면 35개의 내장 테마를 모두 활성화할 수 있어요.

app.css

@import "tailwindcss";
@plugin "daisyui" {
  themes: all;
}

테마 비활성화

예를 들어 dark 테마를 끄려면 목록에서 빼면 돼요. 그러면 light 테마만 포함돼요.

app.css

 @import "tailwindcss";
 @plugin "daisyui" {
-  themes: light --default, dark --prefersdark;
+  themes: light --default;
 }

어떤 이유로 모든 테마를 끄고 daisyUI 색상까지 모두 제거하려면 themes를 false로 설정해요.

app.css

@import "tailwindcss";
@plugin "daisyui" {
  themes: false;
}

테마를 페이지의 한 부분에만 쓰는 방법

어떤 요소든 data-theme='THEME_NAME'를 추가하면 그 안의 모든 것이 지정한 테마를 써요. 테마는 중첩할 수 있고 제한도 없어요! HTML의 특정 섹션을 특정 테마만 쓰도록 강제할 수 있죠.

index.html

<html data-theme="dark">
  <div data-theme="light">
    This div will always use light theme
    <span data-theme="retro">This span will always use retro theme!</span>
  </div>
</html>

새 커스텀 테마 추가하는 방법

theme generator로 색을 편집하고 컴포넌트를 미리 본 다음, CSS를 프로젝트에 복사해 넣을 수 있어요. 새 테마를 추가하려면 CSS 파일에서 @plugin "daisyui/theme" {}를 다음 구조로 쓰면 돼요.

app.css

@import "tailwindcss";
@plugin "daisyui";
@plugin "daisyui/theme" {
  name: "mytheme";
  default: true; /* set as default */
  prefersdark: false; /* set as default dark mode (prefers-color-scheme:dark) */
  color-scheme: light; /* color of browser-provided UI */

  --color-base-100: oklch(98% 0.02 240);
  --color-base-200: oklch(95% 0.03 240);
  --color-base-300: oklch(92% 0.04 240);
  --color-base-content: oklch(20% 0.05 240);
  --color-primary: oklch(55% 0.3 240);
  --color-primary-content: oklch(98% 0.01 240);
  --color-secondary: oklch(70% 0.25 200);
  --color-secondary-content: oklch(98% 0.01 200);
  --color-accent: oklch(65% 0.25 160);
  --color-accent-content: oklch(98% 0.01 160);
  --color-neutral: oklch(50% 0.05 240);
  --color-neutral-content: oklch(98% 0.01 240);
  --color-info: oklch(70% 0.2 220);
  --color-info-content: oklch(98% 0.01 220);
  --color-success: oklch(65% 0.25 140);
  --color-success-content: oklch(98% 0.01 140);
  --color-warning: oklch(80% 0.25 80);
  --color-warning-content: oklch(20% 0.05 80);
  --color-error: oklch(65% 0.3 30);
  --color-error-content: oklch(98% 0.01 30);

  /* border radius */
  --radius-selector: 1rem;
  --radius-field: 0.25rem;
  --radius-box: 0.5rem;

  /* base sizes */
  --size-selector: 0.25rem;
  --size-field: 0.25rem;

  /* border size */
  --border: 1px;

  /* effects */
  --depth: 1;
  --noise: 0;
}

CDN을 쓰면서 커스텀 테마를 쓰려면 이렇게 해요.

app.css

:root:has(input.theme-controller[value=mytheme]:checked),[data-theme="mytheme"] {
  /* mytheme is the name of the custom theme */
  color-scheme: light;
  --color-base-100: oklch(98% 0.02 240);
  /* ...rest of CSS variables like above example */
}

기존 테마 커스터마이징하는 방법

내장 테마를 커스터마이징하려면 새 테마를 추가할 때와 같은 구조를 쓰되, 이름을 내장 테마와 같게 해요. 예를 들어 light 테마를 커스터마이징하려면:

app.css

@import "tailwindcss";
@plugin "daisyui";
@plugin "daisyui/theme" {
  name: "light";
  default: true;
  --color-primary: blue;
  --color-secondary: teal;
}

나머지 다른 값들은 원래 테마에서 상속돼요.

특정 테마에 커스텀 스타일 추가하는 방법

특정 테마에서만 요소에 커스텀 스타일을 작성할 수 있어요. 이 예제에서 .my-btn 클래스는 light 테마에서만 이 스타일을 가져요.

app.css

[data-theme="light"] {
  .my-btn {
    background-color: #1EA1F1;
    border-color: #1EA1F1;
  }
  .my-btn:hover {
    background-color: #1C96E1;
    border-color: #1C96E1;
  }
}

특정 테마에 Tailwind의 'dark:' 선택자 적용하는 방법

daisyUI는 Tailwind의 dark: 접두사를 쓰도록 설정할 수 있어요. 예를 들어 daisyUI 다크 테마에서만 padding을 주고 싶다면 dark:p-10을 쓸 수 있어요. 아래 예제에서 'night'가 다크 모드 테마이므로 @variant dark에 추가해요.

app.css

@import "tailwindcss";
@plugin "daisyui" {
  themes: winter --default, night --prefersdark;
}

@custom-variant dark (&:where([data-theme=night], [data-theme=night] *));

index.html

<div class="p-10 dark:p-20">
  I will have 10 padding on winter theme and 20 padding on night theme
</div>

더 알아보기 (Learn more)

themes 목록을 조작하는 것만으로 다크 모드, 전체 테마, 원하는 테마만 골라 쓰는 것까지 모두 제어할 수 있어요. data-theme로 페이지 일부에만 테마를 입히는 트릭도 자주 쓰이니 기억해 두면 유용해요.