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><html></code> or <code><body></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
✗ Incorrect
The dark: prefix applies the style only when dark mode is active, so dark:text-white sets text color to white only in dark mode.
Which Tailwind config option enables toggling dark mode with a CSS class?
AdarkMode: 'media'
BdarkMode: 'class'
CdarkMode: true
DdarkMode: 'toggle'
✗ Incorrect
Setting darkMode: 'class' allows you to toggle dark mode by adding or removing the dark class.
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>
✗ Incorrect
The normal background is bg-blue-500, and dark:bg-blue-900 overrides it in dark mode.
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
✗ Incorrect
Adding the dark class manually in DevTools triggers dark styles when using darkMode: 'class'.
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
✗ Incorrect
With darkMode: 'media', dark styles apply only if the OS is in dark mode. Otherwise, they don't apply.
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.
Practice
(1/5)
1. What does the dark: prefix do in Tailwind CSS?
easy
A. Applies styles only when dark mode is active
B. Applies styles only on hover
C. Applies styles only on small screens
D. Applies styles only when JavaScript is enabled
Solution
Step 1: Understand the dark: prefix purpose
The dark: prefix in Tailwind CSS is used to apply styles only when the website is in dark mode.
Step 2: Compare with other prefixes
Other prefixes like hover: or sm: apply styles on hover or small screens, not related to dark mode.
Final Answer:
Applies styles only when dark mode is active -> Option A
Quick Check:
dark: = dark mode styles [OK]
Hint: Remember dark: means styles for dark mode only [OK]
Common Mistakes:
Confusing dark: with hover: or responsive prefixes
Thinking dark: applies styles always
Not enabling dark mode in config
2. Which of the following is the correct syntax to change text color to white only in dark mode using Tailwind?
easy
A. text-white dark:text-black
B. dark-text-white
C. text-white:dark
D. dark:text-white
Solution
Step 1: Identify correct dark mode syntax
Tailwind uses dark: prefix before the utility class to apply styles in dark mode, so dark:text-white is correct.
Step 2: Check other options for syntax errors
text-white dark:text-black applies white text always and black text in dark mode, which is reversed. Options B and C have invalid syntax.
Final Answer:
dark:text-white -> Option D
Quick Check:
Correct dark mode prefix = dark: [OK]
Hint: Use dark: before utility class, no colon after class [OK]
Common Mistakes:
Placing :dark after class name
Using dash instead of colon in dark prefix
Reversing colors for dark and light modes
3. What will be the background color of the button when dark mode is enabled?
The button has bg-white and dark:bg-gray-800, so in dark mode background changes to gray-800.
Step 2: Analyze text color in dark mode
Text color is text-black normally and dark:text-white in dark mode, so text becomes white.
Final Answer:
Gray-800 background with white text -> Option A
Quick Check:
dark:bg-gray-800 + dark:text-white = Gray-800 background with white text [OK]
Hint: dark: overrides normal styles in dark mode [OK]
Common Mistakes:
Ignoring dark: prefix effects
Mixing text and background colors
Assuming colors stay same in dark mode
4. You wrote this code but dark mode styles are not applying:
<div class="dark:bg-black bg-white">Content</div>
What is the most likely reason?
medium
A. You should use dark-bg-black instead
B. The order of classes is wrong
C. You forgot to enable dark mode in Tailwind config
D. Dark mode styles only work on buttons
Solution
Step 1: Check Tailwind dark mode setup
Dark mode styles require enabling dark mode in Tailwind config file. Without it, dark: classes won't work.
Step 2: Verify class syntax and usage
Class order does not affect dark mode. dark-bg-black is invalid syntax. Dark mode works on any element, not just buttons.
Final Answer:
You forgot to enable dark mode in Tailwind config -> Option C
Quick Check:
Enable dark mode in config = dark styles work [OK]
Hint: Enable dark mode in config before using dark: classes [OK]
Common Mistakes:
Not enabling dark mode in tailwind.config.js
Using wrong class syntax for dark mode
Thinking dark mode only applies to certain elements
5. You want a card component that has a white background and black text in light mode, but in dark mode it should have a dark gray background and light gray text. Which Tailwind classes achieve this correctly?
<div class="?">Card Content</div>
hard
A. bg-gray-900 text-gray-300 dark:bg-white dark:text-black
B. bg-white text-black dark:bg-gray-900 dark:text-gray-300
C. bg-white dark:bg-gray-900 text-gray-300 dark:text-black
D. dark:bg-white dark:text-black bg-gray-900 text-gray-300
Solution
Step 1: Identify light mode styles
Light mode requires white background and black text, so bg-white text-black are correct for light mode.
Step 2: Identify dark mode styles
Dark mode requires dark gray background and light gray text, so dark:bg-gray-900 dark:text-gray-300 apply these styles in dark mode.
Step 3: Check other options for correctness
bg-gray-900 text-gray-300 dark:bg-white dark:text-black reverses light and dark mode colors. bg-white dark:bg-gray-900 text-gray-300 dark:text-black mixes text colors incorrectly. dark:bg-white dark:text-black bg-gray-900 text-gray-300 places dark mode classes before light mode, which is allowed but colors are reversed.
Final Answer:
bg-white text-black dark:bg-gray-900 dark:text-gray-300 -> Option B