Performance: Class-based dark mode strategy
MEDIUM IMPACT
This affects page load speed and rendering performance by controlling when and how dark mode styles are applied.
/* Using class-based dark mode */ @tailwind base; @tailwind components; @tailwind utilities; /* Tailwind config: darkMode: 'class' */ <body class="dark"> <div class="bg-white dark:bg-gray-900 text-black dark:text-white"> Hello World </div> </body>
/* Using media query dark mode */ @tailwind base; @tailwind components; @tailwind utilities; /* Tailwind config: darkMode: 'media' */ <body> <div class="bg-white dark:bg-gray-900 text-black dark:text-white"> Hello World </div> </body>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Media query dark mode | No extra DOM nodes | Triggers reflow on system theme change | Medium paint cost due to style recalculation | [X] Bad |
| Class-based dark mode | Adds one class to <body> | Single reflow on class toggle | Lower paint cost, stable layout | [OK] Good |