Skip to content

Dark theme using the same variable #15746

Discussion options

You must be logged in to vote

Same question here.

In the old Tailwind we could define CSS vars like this:

root {
  --color-primary: #ff0000;
  
  .dark { /* Assuming using class for dark mode, but selector could be changed for data attributes, etc. if needed */
    --color-primary: #660000;
  }
}

This meant that, with some changes to tailwind config, we could use this in out HTML like this:

<div class="bg-primary size-5"></div>
<h2 class="text-primary">My heading</h2>
.. etc ..

... and our themes would automatically adjust to dark mode.

With the new @theme { } way, how do we achieve the same?

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
2 replies
@deebov
Comment options

@wongjn
Comment options

wongjn Jan 23, 2025
Collaborator

Comment options

You must be logged in to vote
1 reply
@wongjn
Comment options

wongjn Jan 23, 2025
Collaborator

Comment options

You must be logged in to vote
6 replies
@melasculla
Comment options

@hades200082
Comment options

@czak
Comment options

@wongjn
Comment options

wongjn Mar 12, 2025
Collaborator

@czak
Comment options

Answer selected by peterparker2005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
6 participants