Performance: Dark variant usage
This affects page load speed and rendering by conditionally applying styles based on user preference or system settings.
Use Tailwind's dark variant: <html class="dark"> with classes like dark:bg-black dark:text-white@media (prefers-color-scheme: dark) { body { background-color: black; color: white; } } .dark body { background-color: black; color: white; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicated dark styles in media queries and classes | None | 0 | Medium paint cost on theme change | [X] Bad |
| Tailwind dark variant with class toggling | None | 0 | Low paint cost on theme change | [OK] Good |
dark: prefix do in Tailwind CSS?dark: prefix purposedark: prefix in Tailwind CSS is used to apply styles only when the website is in dark mode.hover: or sm: apply styles on hover or small screens, not related to dark mode.dark: = dark mode styles [OK]dark: prefix before the utility class to apply styles in dark mode, so dark:text-white is correct.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.dark:text-white -> Option Ddark: [OK]<button class="bg-white dark:bg-gray-800 text-black dark:text-white p-4">Click Me</button>
bg-white and dark:bg-gray-800, so in dark mode background changes to gray-800.text-black normally and dark:text-white in dark mode, so text becomes white.<div class="dark:bg-black bg-white">Content</div>
dark: classes won't work.dark-bg-black is invalid syntax. Dark mode works on any element, not just buttons.<div class="?">Card Content</div>
bg-white text-black are correct for light mode.dark:bg-gray-900 dark:text-gray-300 apply these styles in dark mode.Pass the test and this pattern moves unknown