0
0
Tailwindmarkup~5 mins

Class-based dark mode strategy in Tailwind - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the class-based dark mode strategy in Tailwind CSS?
It is a method where you add a <code>dark</code> class to a parent element (usually <code>&lt;html&gt;</code> or <code>&lt;body&gt;</code>) to enable dark mode styles on child elements using Tailwind's <code>dark:</code> variant.
Click to reveal answer
beginner
How do you enable dark mode using the class strategy in Tailwind's configuration?
In <code>tailwind.config.js</code>, set <code>darkMode: 'class'</code>. This tells Tailwind to look for a <code>dark</code> class on an ancestor element to apply dark styles.
Click to reveal answer
beginner
How do you write a Tailwind class to style text color differently in dark mode?
Use the dark: prefix before the class. For example, text-black dark:text-white means text is black normally and white in dark mode.
Click to reveal answer
intermediate
Why might you prefer class-based dark mode over media-query based dark mode?
Class-based dark mode lets you control dark mode manually (like with a toggle button), independent of the user's system settings. It offers more flexibility.
Click to reveal answer
intermediate
How can you toggle dark mode on a webpage using the class-based strategy?
Add or remove the <code>dark</code> class on the <code>&lt;html&gt;</code> or <code>&lt;body&gt;</code> element using JavaScript, for example: <code>document.documentElement.classList.toggle('dark')</code>.
Click to reveal answer
In Tailwind CSS, what does setting darkMode: 'class' in the config do?
AEnables dark mode styles when a <code>dark</code> class is present on an ancestor element
BAutomatically detects system dark mode preference
CDisables dark mode completely
DApplies dark mode styles only on mobile devices
Which HTML element is commonly used to add the dark class for class-based dark mode?
A<code>&lt;head&gt;</code>
B<code>&lt;footer&gt;</code>
C<code>&lt;html&gt;</code> or <code>&lt;body&gt;</code>
D<code>&lt;nav&gt;</code>
How do you write a Tailwind class to make background blue normally and dark blue in dark mode?
Abg-blue-500 bg-dark:bg-blue-900
Bbg-blue-500 dark:bg-blue-900
Cbg-blue-500 dark-blue-900
Dbg-blue-500 dark:bg-dark-blue-900
What is a benefit of using class-based dark mode over media-query based dark mode?
AIt allows manual toggling of dark mode by the user
BIt requires no JavaScript
CIt automatically matches system preferences
DIt disables light mode completely
Which JavaScript code toggles dark mode using the class-based strategy?
Adocument.querySelector('html').darkMode = true
Bdocument.body.style.background = 'dark'
Cdocument.getElementById('dark').toggle()
Ddocument.documentElement.classList.toggle('dark')
Explain how the class-based dark mode strategy works in Tailwind CSS and how you set it up.
Think about how Tailwind knows when to apply dark styles.
You got /4 concepts.
    Describe the advantages of using class-based dark mode compared to media-query based dark mode.
    Consider user control and flexibility.
    You got /4 concepts.