Theming
How the token-based theme works, and how to switch between light and dark.
What is a theme
Clinia UI's theme is built entirely on CSS custom properties. The @clinia/tailwindcss package defines every design token as a CSS variable, such as --primary, --background or --radius, and then bridges them into Tailwind v4 utility classes through an @theme inline block:
@theme inline {
--color-primary: var(--primary);
--color-background: var(--background);
--color-foreground: var(--foreground);
--radius-md: var(--radius);
/* ... */
}Tailwind utility classes like bg-primary, text-foreground, and rounded-md resolve to these live CSS variables at runtime. Switching themes changes one class on the <html> element, with no JavaScript re-rendering and no class toggling on individual components.
For the tokens themselves and what each one carries, see Colour.
Light and dark
Clinia UI uses a class-based dark mode strategy. Add class="dark" to the <html> element to activate the dark theme:
<html class="dark">All colour tokens have dark-mode overrides defined inside a .dark selector in the theme CSS, so the switch is automatic for every component, including the ones rendered across this design guide.
Light sections inside dark
Add class="light" to any element to keep it in the light theme on a dark page. Tokens inherit, so the nearest .light or .dark ancestor wins:
<html class="dark">
<section class="light">…</section>
</html>With next-themes
The recommended approach for Next.js apps is to use next-themes, which handles system preference detection, persistence, and hydration:
pnpm add next-themesWrap your root layout with the ThemeProvider:
// app/layout.tsx
import { ThemeProvider } from "next-themes"
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<body>
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
{children}
</ThemeProvider>
</body>
</html>
)
}The suppressHydrationWarning prop on <html> prevents React from warning about the mismatch between server-rendered and client-resolved theme classes.
Keep disableTransitionOnChange: it turns CSS transitions off while the theme class swaps, so every colour changes at once instead of fading unevenly.