vert-ui
Browse docs
All guides

Theming

Switch themes and tones at runtime with a tiny, SSR-safe provider — or drive it yourself from plain CSS.

Model

One theme, one tone

Every component reads semantic CSS variables. Two attributes on <html> pick which values those variables hold:

  • data-theme selects a preset — vert, slate, sand, midnight, rose or ocean.
  • data-tone selects light or dark. A system preference resolves to the OS setting.

Because the values are plain CSS custom properties, switching is instant, needs no re-render and composes with any framework.

Install

Add the theme and the provider

npx shadcn add @vert/vert @vert/vert-theme

The vert item ships the token engine and presets; vert-theme ships the React provider. Import both after Tailwind in your CSS entry.

React

Drop in the provider

import { ThemeProvider } from "@/components/vert-ui/theme-provider"

export function RootLayout({ children }) {
  return (
    <ThemeProvider defaultTheme="vert" defaultTone="system">
      {children}
    </ThemeProvider>
  )
}

Wrap your app once. The provider writes the attributes to <html>, persists the choice in localStorage and follows the OS while the preference is system.

No flash

Apply the theme before first paint

Render the inline script as the first thing in your document head so the stored theme is applied before the page paints — no flash of the wrong colors.

// TanStack Start — add to the root route's head()
import { getThemeScript } from "@/components/vert-ui/theme-provider"

head: () => ({
  scripts: [{ children: getThemeScript() }],
})

// Anywhere else — drop the component into <head> before your app
import { ThemeScript } from "@/components/vert-ui/theme-provider"

<head>
  <ThemeScript />
</head>

API

Read and set the theme

import { useTheme } from "@/components/vert-ui/theme-provider"

function ThemeControls() {
  const { theme, tone, resolvedTone, setTheme, setTone } = useTheme()

  return (
    <div>
      <select value={theme} onChange={(e) => setTheme(e.target.value)}>
        <option value="vert">Vert</option>
        <option value="slate">Slate</option>
        <option value="sand">Sand</option>
        <option value="midnight">Midnight</option>
        <option value="rose">Rose</option>
        <option value="ocean">Ocean</option>
      </select>

      <button onClick={() => setTone(tone === "dark" ? "light" : "dark")}>
        {resolvedTone === "dark" ? "Light" : "Dark"} mode
      </button>
    </div>
  )
}

useTheme() returns theme, tone, the concrete resolvedTone and the current systemTone, plus setTheme / setTone.

Preview

Try it live

CSS only

Without React

Not on React? Set the same attributes yourself — the tokens do the rest. Persist the choice wherever you like and restore it before paint.

<!-- light (default) -->
<html data-theme="vert" data-tone="light">

<!-- dark tone -->
<html data-theme="vert" data-tone="dark">

<!-- a different preset -->
<html data-theme="slate" data-tone="dark">

The dark: variant follows data-tone

The theme remaps Tailwind's dark: variant to [data-tone='dark'], so dark:bg-surface responds to your tone attribute — not the OS setting. An explicit tone always wins.

Advanced

Custom presets and keys

ThemeProvider accepts themes, storageKey, themeAttribute, toneAttribute and darkClassName, so you can ship your own presets or namespace the stored keys per app.

Re-skin a preset by editing the CSS variables in styles/themes/<name>.css — change --brand and the whole interface follows.