What is the best approach for adding your own themes for Tailwind in the same manner as dark mode?
The dark
class is included within the HTML tag to signify that the page is now in dark mode, and we use the dark:
selector when defining classes to style in that mode.
My question - how do we go about adding additional classes to the HTML tag and using additional custom selectors within styles to style in that particular variant?
I've read some plugin and variant documentation on the official Tailwind site, but it is not too clear what the right approach is here.
The right approach is opinion based. You may use classes on
html
orbody
or any "global" selector, use customdata-attributes
(likedata-theme
) etcHere is example where I am using
:has
CSS selector to switch theme based on.theme
elementIn order to use custom variant write simple plugin for it
Using Javascript toggle
theme--red
ortheme--green
classes on.theme
element