Skip to content

Problem with dark mode because Tailwind v4 loads two CSS versions in dev mode #18539

@fabian-hiller

Description

@fabian-hiller

What version of Tailwind CSS are you using?

For example: v4.1.11

What build tool (or framework if it abstracts the build tool) are you using?

For example: Vite v5.4.14 and @tailwindcss/vite v4.1.11

What version of Node.js are you using?

For example: v22.12.0

What browser are you using?

For example: Brave

What operating system are you using?

For example: macOS

Reproduction URL

I am not able to reproduce it in a minimal demo, but still hope this issue provides some value. The issue occurred after migrating the Valibot docs in this PR to Tailwind v4.

Describe your issue

I am using @custom-variant dark (&:where(.dark, .dark *)) to overwrite the default prefers-color-scheme behavior, but Tailwind loads inconsistent CSS code in dev mode. It loads an index.css file from the Tailwind node_modules folder, as well as my own custom root.css file, which includes @import 'tailwindcss'. My CSS file includes the correct dark mode declarations, but the index.css file does not, which mixes up the declarations if you choose a color mode that is not the current prefers-color-scheme.

Image

So I ended up with two versions of Tailwind v4.1.11, each with CSS declarations that contradict each other.

Image

I have already tried various methods of debugging and fixing it, but with no success.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions