How to use daisyUI themes?
@plugin "daisyui" {
themes: light --default, dark --prefersdark, cupcake;
}
<html data-theme="cupcake"></html>
I suggest using theme-change, so you can switch themes and save selected theme in local storage.
@plugin "daisyui" {
themes: light --default, dark --prefersdark, 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, abyss, silk;
}
light
(or dark
for dark mode) but you can change the default theme from tailwind.config.js cupcake
will be the default theme for light modedark
will be the default theme for dark modecmyk
can be applied on any HTML tag with data-theme='cmyk'
@plugin "daisyui" {
themes: cupcake --default, dark --prefersdark, cmyk;
}
themes
config to false. @plugin "daisyui" {
themes: light --default;
}
themes
config to an empty array. @plugin "daisyui" {
themes: false;
}
data-theme='THEME_NAME'
to any element and everything inside will have your theme. You can nest themes and there is no limit! You can force a section of your HTML to only use a specific theme. <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>
tailwind.config.js
file. In the below example, I added a new theme called mytheme
and I'm also including dark
and cupcake
themes. mytheme
) will be the default theme.dark
theme will be the default theme for dark mode.primary
button). You can also add optional color names to have full control over all colors.
@plugin "daisyui/theme" {
name: "mytheme";
default: false; /* 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 */
--gloss: 1;
--noise: 0;
}
[data-theme="mytheme"] .btn {
border-width: 2px;
border-color: black;
}
light
theme and change its primary
and secondary
colors: @plugin "daisyui/theme" {
name: "light";
default: true;
--color-primary: blue;
--color-secondary: teal;
}
module.exports = {
//...
daisyui: {
themes: [
{
light: {
...require("daisyui/src/theming/themes")["light"],
".btn-twitter": {
"background-color": "#1EA1F1",
"border-color": "#1EA1F1",
},
".btn-twitter:hover": {
"background-color": "#1C96E1",
"border-color": "#1C96E1",
},
},
},
],
},
}
dark:
selector in your code. To achieve this, modify your tailwind.config.js
file to include the darkMode parameter. Ensure that the dark: selector applies to the daisyUI theme you designate as dark. In the example below, we have 'winter' and 'night' themes. Since 'night' is the dark theme, we configure it as shown: module.exports = {
content: ['./src/**/*.{astro,html,svelte,vue,js,ts,jsx,tsx}'],
plugins: [require('daisyui')],
theme: { ... },
daisyui: {
themes: ['winter', 'night']
},
darkMode: ['selector', '[data-theme="night"]']
}