0
0
Tailwindmarkup~5 mins

Dark variant usage in Tailwind - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the dark: variant in Tailwind CSS?
The dark: variant applies styles only when the user's system or website is in dark mode, allowing easy creation of dark theme designs.
Click to reveal answer
beginner
How do you enable dark mode support in Tailwind CSS?
You enable dark mode by setting <code>darkMode: 'class'</code> or <code>darkMode: 'media'</code> in the <code>tailwind.config.js</code> file. <code>'class'</code> uses a CSS class like <code>dark</code> on the root element, while <code>'media'</code> uses the user's system preference.
Click to reveal answer
beginner
Example: What does bg-white dark:bg-gray-900 do?
It sets the background color to white normally, but changes it to dark gray (#1a202c) when dark mode is active.
Click to reveal answer
intermediate
Why use darkMode: 'class' instead of 'media'?
Using <code>'class'</code> lets you toggle dark mode manually by adding or removing the <code>dark</code> class on an element, giving more control than relying on system settings.
Click to reveal answer
beginner
How can you test dark variant styles in the browser?
If using <code>darkMode: 'class'</code>, add the <code>dark</code> class to the <code>&lt;html&gt;</code> or <code>&lt;body&gt;</code> element in DevTools to see dark styles. For <code>'media'</code>, toggle your OS dark mode setting.
Click to reveal answer
What does the Tailwind class dark:text-white do?
ASets background color to white in dark mode
BAlways sets text color to white
CSets text color to white only in dark mode
DDisables text color in dark mode
Which Tailwind config option enables toggling dark mode with a CSS class?
AdarkMode: 'media'
BdarkMode: 'class'
CdarkMode: true
DdarkMode: 'toggle'
If you want a button to have a blue background normally and a dark blue background in dark mode, which is correct?
A<code>bg-blue-500 dark:bg-blue-900</code>
B<code>dark:bg-blue-500 bg-blue-900</code>
C<code>bg-blue-900 dark:bg-blue-500</code>
D<code>bg-blue-500 bg-blue-900</code>
How can you manually test dark mode styles if using darkMode: 'class'?
AAdd <code>dark</code> class to <code>html</code> or <code>body</code> in DevTools
BRestart the browser
CToggle OS dark mode setting
DUse a special dark mode browser
What happens if you use dark:bg-black but your config is darkMode: 'media' and your OS is in light mode?
ABackground will be black
BBackground will be transparent
CBackground will flash black briefly
DBackground will not change to black
Explain how to use the dark variant in Tailwind CSS to create a dark mode style for a text element.
Think about configuration and how to write classes with dark:
You got /4 concepts.
    Describe the difference between darkMode: 'class' and darkMode: 'media' in Tailwind CSS and when you might use each.
    Consider control vs automatic behavior
    You got /4 concepts.