0
0
Tailwindmarkup~20 mins

Class-based dark mode strategy in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dark Mode Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does Tailwind's class-based dark mode work?
In Tailwind CSS, when using the class-based dark mode strategy, which HTML element should you add the dark class to enable dark styles for the entire page?
AThe <code>&lt;body&gt;</code> element
BThe <code>&lt;html&gt;</code> element
CThe <code>&lt;head&gt;</code> element
DThe <code>&lt;main&gt;</code> element
Attempts:
2 left
💡 Hint
Think about which element wraps the whole page content and can control styles globally.
📝 Syntax
intermediate
2:00remaining
Which Tailwind config enables class-based dark mode?
Given this Tailwind CSS configuration snippet, which option correctly enables class-based dark mode?
Tailwind
module.exports = {
  darkMode: ???,
  theme: {
    extend: {},
  },
  plugins: [],
}
Afalse
B"media"
Ctrue
D"class"
Attempts:
2 left
💡 Hint
The value should be a string that tells Tailwind to use a CSS class for dark mode.
rendering
advanced
2:00remaining
What is the visual output when toggling dark mode class?
Consider this HTML snippet using Tailwind with class-based dark mode enabled:
<html class="dark">
  <body>
    <div class="bg-white dark:bg-gray-800 text-black dark:text-white p-4">
      Hello, dark mode!
    </div>
  </body>
</html>
What background and text colors will the <div> have when the dark class is present on <html>?
ABackground: gray-800, Text: white
BBackground: white, Text: black
CBackground: gray-800, Text: black
DBackground: white, Text: white
Attempts:
2 left
💡 Hint
Remember that the dark: prefix applies styles only when the dark class is present.
selector
advanced
2:00remaining
Which CSS selector does Tailwind use for class-based dark mode?
When Tailwind generates CSS for class-based dark mode, which selector pattern does it use to apply dark styles?
A.dark &lt;selector&gt; { ... }
B&lt;selector&gt;.dark { ... }
C.dark > &lt;selector&gt; { ... }
D:root.dark &lt;selector&gt; { ... }
Attempts:
2 left
💡 Hint
Think about how CSS applies styles when a parent has a class.
accessibility
expert
3:00remaining
How to maintain accessibility when toggling dark mode with classes?
When implementing class-based dark mode toggling in Tailwind, which practice best supports accessibility for keyboard and screen reader users?
AReload the page to switch between dark and light modes
BToggle the <code>dark</code> class on <code>&lt;body&gt;</code> without any ARIA attributes
CToggle the <code>dark</code> class on <code>&lt;html&gt;</code> and update <code>aria-pressed</code> on the toggle button accordingly
DUse JavaScript to add inline styles instead of toggling classes
Attempts:
2 left
💡 Hint
Accessibility means informing assistive technologies about state changes.