Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

A custom daisyUI theme leaves every color at the default

Your error

daisyUI custom theme not working: btn-primary and bg-base-100 keep the stock light theme colors2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The theme is still defined in tailwind.config.js

Delete the daisyui key and the require("daisyui") plugin line from tailwind.config.js.

Fix
@import "tailwindcss";
@plugin "daisyui";
@plugin "daisyui/theme" {
  name: "mytheme";
  default: true;
  color-scheme: light;
  --color-base-100: oklch(98% 0.02 240);
  --color-base-content: oklch(20% 0.05 240);
  --color-primary: oklch(55% 0.3 240);
  --color-primary-content: oklch(98% 0.01 240);
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

A daisyUI custom theme that is not working on Tailwind CSS 4 is usually still defined in tailwind.config.js, a file daisyUI 5 no longer reads. Move it into your main CSS file as an @plugin "daisyui/theme" block with a name, default: true and --color-* variables, then make data-theme use that exact name. Applies to daisyUI 5.8 and Tailwind CSS 4.3.

  • Applies to daisyUI 5.8.2, Tailwind CSS 4.3.5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the Tailwind CSS and daisyUI versions the project really uses. Version 4 with version 5 means the theme has to live in CSS (cause 1). If it already does, the name (cause 2) or the variable names (cause 3) are wrong.

Run this first
npm ls tailwindcss daisyui

Then find the line you see in this list and open its fix:

  1. 1The theme is still defined in tailwind.config.jsnpm ls shows tailwindcss@4 and daisyui@5, and your colors sit under a daisyui: { themes: [...] } key in tailwind.config.js
  2. 2data-theme points at a name the CSS never definesThe @plugin "daisyui/theme" block exists, but the data-theme value in your HTML is spelled differently from its name: line, or the block has no default: true and nothing sets data-theme
  3. 3The theme still uses daisyUI 4 variable namesYour CSS sets short variables such as --p, --pc or --b1, or sets only the main colors and leaves text on buttons with poor contrast

What does the error look like?

  • daisyUI custom theme not working: btn-primary and bg-base-100 keep the stock light theme colors
  • data-theme="mytheme" on the html tag has no effect after moving to Tailwind CSS 4
  • Theme colors from a daisyUI 4 project are ignored after npm i -D daisyui@latest

Cause 1 of 3

The theme is still defined in tailwind.config.js

You seenpm ls shows tailwindcss@4 and daisyui@5, and your colors sit under a daisyui: { themes: [...] } key in tailwind.config.js

Check

A daisyUI custom theme stops working on Tailwind CSS 4 when it is written in tailwind.config.js. Tailwind 4 does not pick up a JavaScript config file by itself any more, and daisyUI 5 takes its settings from the CSS file, so the theme object is never seen.

Check
grep -rn --exclude-dir=node_modules "daisyui" --include="*.css" --include="tailwind.config.*" .

Fix

Delete the daisyui key and the require("daisyui") plugin line from tailwind.config.js. In the CSS file that imports Tailwind, load daisyUI and then add the theme as its own @plugin "daisyui/theme" block. The theme generator on the daisyUI site exports this exact format if you want to pick colors visually.

Fix
@import "tailwindcss";
@plugin "daisyui";
@plugin "daisyui/theme" {
  name: "mytheme";
  default: true;
  color-scheme: light;
  --color-base-100: oklch(98% 0.02 240);
  --color-base-content: oklch(20% 0.05 240);
  --color-primary: oklch(55% 0.3 240);
  --color-primary-content: oklch(98% 0.01 240);
}

Verify

Restart the dev server and reload. A btn-primary button now shows your primary color, even with no data-theme attribute, because default: true makes this theme the starting one.

Verify
getComputedStyle(document.documentElement).getPropertyValue('--color-primary')

Confirmed by daisyui.com

Did this fix it?

Cause 2 of 3

data-theme points at a name the CSS never defines

You seeThe @plugin "daisyui/theme" block exists, but the data-theme value in your HTML is spelled differently from its name: line, or the block has no default: true and nothing sets data-theme

Check

With the block in place, a custom daisyUI theme still shows stock colors when nothing selects it. daisyUI switches themes through a data-theme attribute whose value must equal the theme's name, or through default: true inside the block.

Check
grep -rn --exclude-dir=node_modules -e "data-theme" -e "name: " --include="*.html" --include="*.css" --include="*.vue" --include="*.tsx" --include="*.jsx" .

Fix

Pick one spelling and use it in both places. Set data-theme on the html element for the whole page, or on a single container when only one section should use the theme. Keep default: true if visitors should get the theme before any switcher runs.

Fix
<html data-theme="mytheme">
  <body>
    <button class="btn btn-primary">Save</button>
  </body>
</html>

Verify

The browser console prints mytheme, and the Styles pane for the html element lists the --color-* values from your block.

Verify
document.documentElement.dataset.theme

Confirmed by daisyui.com

Did this fix it?

Cause 3 of 3

The theme still uses daisyUI 4 variable names

You seeYour CSS sets short variables such as --p, --pc or --b1, or sets only the main colors and leaves text on buttons with poor contrast

Check

daisyUI 5 renamed all of its color variables and dropped the automatic calculation of *-content colors. A custom theme copied from a daisyUI 4 project therefore writes values that no component reads, and missing -content colors are not filled in.

Check
grep -rnE -- "--(p|pc|s|sc|a|ac|n|nc|b1|b2|b3|bc)\s*:" --include="*.css" --exclude-dir=node_modules .

Fix

Rename every short variable to its new form: --p becomes --color-primary, --pc becomes --color-primary-content, --b1 becomes --color-base-100 and --bc becomes --color-base-content. Write whole color values in any CSS format, and give each color you set a matching -content color.

Fix
/* daisyUI 4 */
--p: 49.12% 0.3096 275.75;
/* daisyUI 5 */
--color-primary: oklch(49.12% 0.309 275.75);
--color-primary-content: oklch(89.824% 0.061 275.75);

Verify

Buttons, badges and alerts show your colors, and their text uses the -content value you wrote instead of a guess.

Verify
getComputedStyle(document.documentElement).getPropertyValue('--color-primary-content')

Confirmed by daisyui.com

Did this fix it?

How do I stop it coming back?

  • Keep every daisyUI setting in the one CSS file that holds @import "tailwindcss", and delete tailwind.config.js once nothing loads it.
  • Generate new themes with the daisyUI theme generator so the variable names always match the installed major version.
  • Pin daisyui and tailwindcss to the same major line in package.json and upgrade both together with the official upgrade guide.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.