Problem: Toggle dark scheme.

Solution#

html
<script>
  document.documentElement.classList.toggle("dark", localStorage.theme === "dark");
</script>
<body class="bg-white dark:bg-slate-950 text-slate-900 dark:text-slate-100">…</body>

Why this works#

Class strategy: dark class on <html> + dark: variants everywhere.

Variants#

  • Responsive: add screen prefixes to the core classes
  • Dark: pair each color utility with its dark: twin
  • Animated: add transition + a state variant for motion

cookbook/index|Cookbook index · utilities/index|Utilities reference · patterns/index|Layout patterns