HTML & CSS · Senior · Question 43 of 75

How do you make Tailwind v4's dark mode follow a .dark class instead of the system setting?

Explanation

In v4, variants are defined in CSS with @custom-variant. That way dark: can be bound to a class or an attribute ([data-theme=dark]). darkMode: 'class' is a v3 tailwind.config.js option and doesn't work inside @theme. :where() keeps specificity from increasing.

Further reading

Problem with a question

HTML & CSS · Senior · question 43

Test yourself

Take the HTML & CSS · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz