Tailwind CSS
/Intermediate
Dark Mode Colors
Definition
Using the `dark:` variant to specify alternative text and background colors when the user's operating system or app is in Dark Mode.
Explain Like I'm New
It's literally magic. `bg-white dark:bg-gray-900`. If the user's iPhone is in Light Mode, the box is white. If they flip their iPhone to Dark Mode, Tailwind instantly changes the box to dark gray.
Real World Example
Creating a Card component: `<div class="bg-white text-black dark:bg-slate-800 dark:text-white">`.
Common Use Cases
- •Supporting modern OS preferences
- •Night-reading modes
Interactive Example
Interview Questions
basic
- What variant prefix do you put in front of a class to make it apply ONLY in dark mode?
intermediate
- Do you have to write a separate CSS file or `@media` query to make dark mode work in Tailwind?