dark:bg-gray-800, what happens when the user switches to dark mode in their system settings?By default, Tailwind uses the prefers-color-scheme: dark media query to apply dark: variant styles automatically when the user's system is set to dark mode, but only if the dark class is present on the <html> or <body> element when using the 'class' strategy.
<div class="text-black dark:text-white">Hello</div>
What color will the text be when the page is in dark mode and the
dark class is on the <html> element?<div class="text-black dark:text-white">Hello</div>The dark:text-white class applies only when the dark class is present on a parent. It overrides the base text-black color, making the text white in dark mode.
<section> only when dark mode is active. Which Tailwind class achieves this?<section class="p-4 ???">Content</section>The correct syntax is dark:p-8 which applies padding 8 only in dark mode. Other options are invalid Tailwind classes.
Dark variant usage helps maintain good contrast between text and background colors in dark mode, making content easier to read for everyone, including users with low vision.
dark class?Tailwind's default dark mode strategy uses the prefers-color-scheme media query to detect if the user has set their system to dark mode, applying dark styles automatically without extra JavaScript or manual class toggling.