Flagship themes and defineTheme
A flagship is a complete, ready-made theme that ships with @ghostvue/themes. Each one restyles every themed component through tokens alone: color, corner roundness, density, motion, elevation, and gradients. Your markup stays the same. GhostVue has four built-in themes: the hand-authored default and the calm, vibrant, and mono flagships. Pick one with data-ghost-theme, or generate your own with defineTheme.
Compare the flagships
The same small screen under each built-in theme, in light and dark:
defaultHand-authored baselineInvite a teammate
AdminInvite a teammate
AdmincalmRefined enterpriseInvite a teammate
AdminInvite a teammate
AdminvibrantStriking expressiveInvite a teammate
AdminInvite a teammate
AdminmonoCrisp monochromeInvite a teammate
AdminInvite a teammate
Admindata-ghost-theme | Intent | Knobs |
|---|---|---|
calm | Refined enterprise | hue 215, compact, roundness 0.5, motion 0.6, elevation subtle, gradient none, interactivity subtle |
vibrant | Striking expressive | hue 292, comfortable, roundness 1, motion 1, elevation dramatic, gradient aurora, interactivity expressive |
mono | Crisp monochrome | #171717, neutralTint: 'none', roundness 0, motion 0.45, elevation subtle, gradient none, interactivity subtle |
mono keeps default status hues so danger and success stay distinguishable. These files are package exports:
@ghostvue/themes/calm.css@ghostvue/themes/vibrant.css@ghostvue/themes/mono.css
default remains the published baseline for applications; see the default theme. The docs boot into default on first paint and ship a switcher for default | calm | vibrant | mono. A blocking inline script restores a persisted choice from localStorage before paint.
Apply and nest
Import recipes plus every theme the page might show, then set data-ghost-theme on the host before first paint:
import '@ghostvue/themes/default.css'
import '@ghostvue/themes/calm.css'
import '@ghostvue/themes/vibrant.css'
import '@ghostvue/themes/mono.css'<main class="ghost-theme" data-ghost-theme="calm">…</main>.ghost-theme without data-ghost-theme is default. Named sheets match :where([data-ghost-theme='name']). .ghost-themed-scope is a recipe scope only (display: contents); it is not a token host, so a themed wrapper inside a nested flagship inherits that flagship. data-ghost-mode and data-ghost-density stay orthogonal. Unset mode still follows prefers-color-scheme. A theme's density default applies only under that data-ghost-theme.
startThemeTransition remains mode-only. Theme switches are setAttribute('data-ghost-theme', name).
To avoid shipping every palette up front, keep the first-paint palette in the initial CSS and import() the others, including sheets that defineTheme wrote, when the user selects them. See load palettes on demand.
Generate a theme
defineTheme turns a small brand input into a complete token sheet scoped to data-ghost-theme. It runs in Node at build time, not in the browser.
import { writeFileSync } from 'node:fs'
import { defineTheme } from '@ghostvue/themes/define'
const acme = defineTheme({ name: 'acme', primary: '#0f766e', roundness: 0.5 })
writeFileSync('src/acme.css', acme.css)This is the sheet that call produces, rendered on the same screen as the flagships above. The docs build runs the call itself, so the preview always matches the current generator.
A thin CLI wraps the same function:
pnpm --filter @ghostvue/themes define-theme --name acme --primary '#0f766e' --out acme.cssprimary is an OKLCH hue in [0, 360] or an absolute CSS color. Hue-only inputs keep the library's role lightness and chroma. Color strings become the light seed and donate hue/chroma to the independently-tuned dark template lightness. Defaults: neutralTint from the primary hue at library neutral chroma; status seeds from default; roundness = 1; density = 'comfortable'; motionIntensity = 1; elevation = 'standard'; gradient = 'subtle'; interactivity = 'subtle'; fontFamily unset (the system UI sans stack).
Invalid names, hues, colors, enums, ranges, or font family lists throw. After the generator walks *.fg / on-color steps (and action fills so white or ink labels can meet AA), it throws if any evaluateContrast pair still fails WCAG 2 AA.
Set the typeface
fontFamily gives the theme its own typeface. It takes a CSS font-family list and sets both family tokens that themed components read, under [data-ghost-theme='name'] only:
const ledger = defineTheme({
name: 'ledger',
primary: '#0f766e',
fontFamily: '"JetBrains Mono", ui-monospace, monospace',
})pnpm --filter @ghostvue/themes define-theme --name ledger --primary '#0f766e' \
--font-family '"JetBrains Mono", ui-monospace, monospace' --out ledger.css| Token | Read by |
|---|---|
--ghost-type-family-sans | Body text, inputs, menus, dialogs, and other component text |
--ghost-action-label-family | Action labels: buttons, badges, checkboxes, and similar parts |
fontFamily does not set --ghost-type-family-mono, the code face that prose inline code, bare pre, and kbd read. A theme that changes its text face rarely wants to change its code face. To change the code face, override --ghost-type-family-mono on the palette host. The token is unrelated to the mono flagship theme (@ghostvue/themes/mono.css), which is a palette, not a typeface.
Each entry is a quoted family name ("JetBrains Mono", "Foo, Inc.") or plain identifiers (ui-monospace, Helvetica Neue). Commas inside quotes stay part of the name. Quote a name whose words start with a digit, such as "3270 Mono"; unquoted, it throws. The generator writes the list verbatim into the stylesheet, so ;, {, }, <, >, backslashes, parentheses, newlines, unbalanced quotes, empty entries, and CSS-wide keywords such as inherit throw. fontFamily does not load or bundle the font: load it with @font-face or your font provider, and end the list with a generic family as a fallback. Leaving fontFamily out generates the same CSS as before.
fontFamily does not set --ghost-type-family-mono, the code face used by GhostCodeBlock: a theme that changes its text face rarely wants a different code face. Override that token on the palette host when you want one. It is unrelated to the mono flagship theme (@ghostvue/themes/mono.css), which is a monochrome palette, not a monospace one.
To change the typeface without defineTheme, override both tokens by hand. Setting only --ghost-type-family-sans leaves buttons, badges, and checkboxes on the system stack. Put the override on the palette host, usually :root, so dialogs, menus, and other content that teleports to <body> picks it up too (see token overrides and the palette host):
:root {
--ghost-type-family-sans: 'JetBrains Mono', ui-monospace, monospace;
--ghost-action-label-family: 'JetBrains Mono', ui-monospace, monospace;
}Gradient hues
The gradient option picks how the decorative gradients behind the data-gradient recipes (accent, aurora, and border) are built. They do not stay in the primary hue. By design, subtle and aurora sweep from the primary into the theme's status hues:
gradient | --ghost-gradient-accent | --ghost-gradient-aurora wells |
|---|---|---|
subtle | primary → info | primary, info, success |
aurora | primary → info → danger | primary, info, danger, primary |
none | solid primary | plain surface, no wells |
--ghost-gradient-border copies the accent gradient. The status hues come from status, or from default when you leave it out, so with a warm primary such as #c2410c the accent gradient still runs into the default sky blue info hue, and with aurora it ends on red. Setting status.info or status.danger moves those stops, and also the info and danger badges and alerts and the danger buttons. The action gradients (--ghost-gradient-action-*) are not affected: they stay in one hue so their labels keep AA contrast.
For an on-brand sweep, keep the flavor and override the decorative gradient variables on the theme host. The generated sheet writes resolved colors, so --ghost-gradient-border does not follow an accent override; set it too:
[data-ghost-theme='acme'] {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #c2410c, #f59e0b);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #fed7aa 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #fde68a 0%, transparent 48%);
}Generated sheets sit in the ghostvue-theme cascade layer, so an unlayered rule like this wins without extra specificity. It applies in light and dark mode alike. For separate dark stops, give the dark values their own rules and cover every way a region can be dark: following a dark system preference, or data-ghost-mode="dark" on the theme host, on an ancestor of it, or on a subtree inside it. A forced-light region inside a dark one needs the light values again. A subtree with its own data-ghost-mode gets the generated values back, so each rule sets all three variables:
[data-ghost-theme='acme'] {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #c2410c, #f59e0b);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #fed7aa 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #fde68a 0%, transparent 48%);
}
@media (prefers-color-scheme: dark) {
[data-ghost-theme='acme'] {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #fb923c, #fde047);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #7c2d12 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #713f12 0%, transparent 48%);
}
}
[data-ghost-theme='acme'][data-ghost-mode='dark'],
[data-ghost-mode='dark'] [data-ghost-theme='acme']:not([data-ghost-mode]) {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #fb923c, #fde047);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #7c2d12 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #713f12 0%, transparent 48%);
}
@scope ([data-ghost-theme='acme']) to ([data-ghost-theme]) {
[data-ghost-mode='dark'] {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #fb923c, #fde047);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #7c2d12 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #713f12 0%, transparent 48%);
}
}
[data-ghost-theme='acme'][data-ghost-mode='light'],
[data-ghost-mode='light'] [data-ghost-theme='acme']:not([data-ghost-mode]) {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #c2410c, #f59e0b);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #fed7aa 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #fde68a 0%, transparent 48%);
}
@scope ([data-ghost-theme='acme']) to ([data-ghost-theme]) {
[data-ghost-mode='light'] {
--ghost-gradient-accent: linear-gradient(135deg in oklch, #c2410c, #f59e0b);
--ghost-gradient-border: var(--ghost-gradient-accent);
--ghost-gradient-aurora:
radial-gradient(in oklch at 14% 18%, #fed7aa 0%, transparent 52%),
radial-gradient(in oklch at 86% 12%, #fde68a 0%, transparent 48%);
}
}Keep the rules in this order. Leave out the media rule only when every themed region pins its mode with data-ghost-mode. A mode on the theme host itself always wins over one on an ancestor. The @scope blocks cover mode subtrees inside the theme host and stop at a nested host of another theme, which keeps its own gradients. @scope needs Chrome 118, Safari 17.4 or Firefox 146; older browsers skip those blocks, so a mode subtree there keeps the stops of the region around it. One case is not covered: when both modes are set on ancestors above the theme host, the forced-light rule wins even if dark is the nearer one. Put the mode on the theme host itself in that layout.
gradient: 'none' makes the accent and border gradients a flat primary fill and the aurora gradient the plain surface color, so data-gradient="aurora" blends into the page.
Packaging notes
defineTheme is a Node-only generator in @ghostvue/themes/define. It is not re-exported from @ghostvue/themes, so application bundles cannot pull culori by accident. culori stays a themes devDependency, but its code is bundled into dist/define.js; see packages/themes/THIRD_PARTY_NOTICES.md for the MIT license text.
default remains hand-authored DTCG; flagships are checked-in defineTheme calls compiled at package build. The signed-off contract is ADR 0008.