Dark mode
Dark mode switches the theme's variables, not your classes: turn it on, follow the system setting without a flash, and why the default theme's dark is neutral.
Dark mode in Ritla UI is a mode of the theme's variables, not a second set of classes. The same bg-surface-lowest or text-gray-txt-primary resolves to a light value or a dark one depending on where it sits, and the few styles that need a dark variant use theme-dark:, never Tailwind's dark:, which stays yours.
Turn it on#
Ritla UI turns dark on the same switch as your app. npx ritla init asks which switch that is and imports the theme's dark colors and the theme-dark: variant for that switch, and only that one:
| Your app switches with | Put this on <html> or any ancestor |
|---|---|
A .dark class (the default, the shadcn convention) | class="dark" |
A data-theme attribute | data-theme="dark" |
| The system setting only | Nothing: the reader's system setting decides. class="light" or data-theme="light" on <html> keeps a page light |
Everything inside the switched element renders dark. Its absence, the class light or data-theme="light" renders light.
<html lang="ar" dir="rtl" class="dark">With the class or the attribute, the switch sits on an ancestor, so a single section can differ from the page: a light card inside a dark page is class="light" (or data-theme="light") on that card. With the system setting, the whole page follows the reader's system.
Follow the system setting#
If your app has its own light and dark toggle, use the class or the attribute switch, and read the reader's preference before the first paint, so the page never flashes light before turning dark. A small inline script in <head> does it:
<script> const stored = localStorage.getItem("theme"); const dark = stored ? stored === "dark" : matchMedia("(prefers-color-scheme: dark)").matches; document.documentElement.classList.toggle("dark", dark);</script>With the data-theme switch, set document.documentElement.dataset.theme to "dark" or "light" instead. With Next.js, put the script in the root layout and add suppressHydrationWarning to <html>, since the class is set before React hydrates.
Neutral, not tinted#
The default theme's dark mode is a neutral gray rather than a blue-black, so brand colors and status colors keep the meaning they have in light mode.
Previews#
Every component preview on this site takes the same switch, so you can check a component in dark mode, in Arabic, with Arabic-Indic digits, before you install it.