Logo hdtoledo
hdtoledo.dev
Módulos_del_Sistema
MÓDULO_TEÓRICO

Dark Mode and Arbitrary Values

Dark Mode and Arbitrary Values

Breaking the Rules: Limitless Customization

What happens when you need a hyper-specific brand hex code or custom drop shadow? Or how do you empower users to toggle between Light and Dark mode with one click?


1. Arbitrary Value Syntax [...]

Tailwind lets you inject exact CSS values using square brackets:

  • bg-[#070913]: Exact hexadecimal color.
  • top-[72px]: Pixel-precise positioning offset.
  • grid-cols-[260px_1fr]: Custom 2-track grid with 260px sidebar.
  • shadow-[0_0_30px_rgba(0,240,255,0.3)]: Custom glowing ambient light.
html
<!-- Element with precise arbitrary values --> <div class="w-[340px] h-[180px] bg-[#0d111e] shadow-[0_0_40px_rgba(0,240,255,0.15)] rounded-[24px] p-[28px] border border-[#00f0ff]/30"> <p class="text-[13px] font-mono text-[#00f0ff]">EXACT ARBITRARY TOKEN</p> </div>

2. Dark Mode with the dark: Variant

With darkMode: 'class' declared in your tailwind.config, toggling themes only requires toggling the dark class on the root <html> element:

html
<!-- Automatically adapts based on 'dark' class --> <div class="bg-white text-slate-900 dark:bg-slate-950 dark:text-white border border-slate-200 dark:border-slate-800 p-6 rounded-2xl transition-colors duration-300"> <h3 class="text-lg font-bold">Multi-Theme Card</h3> <p class="text-sm text-slate-600 dark:text-slate-400 mt-1"> This component adapts automatically when dark mode is toggled. </p> </div>