Skip to content

Enable Tailwind dark: with data-theme attribute#6334

Merged
SteffenDE merged 2 commits into
phoenixframework:mainfrom
rubas:patch-1
Jul 7, 2025
Merged

Enable Tailwind dark: with data-theme attribute#6334
SteffenDE merged 2 commits into
phoenixframework:mainfrom
rubas:patch-1

Conversation

@rubas

@rubas rubas commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

The Theme Switcher root.html.heex uses the data-theme attribute to toggle between light/dark themes.
Tailwind's dark: variant expects per default a class="dark" though.

This custom variant makes Tailwind's dark: work with data-theme="dark".

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

Without this, the dark: utility will not work, even DaisyUI themes switch correctly.

👉 Reference: https://tailwindcss.com/docs/dark-mode#using-a-data-attribute

@Gazler

Gazler commented Jul 3, 2025

Copy link
Copy Markdown
Member

This is how daisyUI recommends doing it too
https://daisyui.com/docs/themes/#how-to-apply-tailwinds-dark-selector-for-specific-themes

Comment thread installer/templates/phx_assets/app.css Outdated
@SteffenDE SteffenDE merged commit 92b9389 into phoenixframework:main Jul 7, 2025
6 checks passed
@SteffenDE

Copy link
Copy Markdown
Member

Thank you! 🙌🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants