UnoCSS
Configure the UnoCSS preset, file scanning, Wind3 and Wind4 compatibility, and semantic color variable generation.
presetMoraine(), exported from moraine/unocss, integrates Moraine with UnoCSS. It maps semantic colors, border radiuses, shadows, animation keyframes, z-index utilities, and state variants into UnoCSS.
Installation and config#
In an existing Solid/Vite project, install Moraine and the UnoCSS integration:
Add presetMoraine() alongside your Wind preset (presetWind4 or presetWind3). The preset targets Wind4 by default; set wind3: true for Wind3. It does not detect which Wind preset is installed. Scan your application files and Moraine’s published classes explicitly:
Solid and Vite integration#
Place unocss.config.ts and vite.config.ts in the application root. Register the UnoCSS plugin before Solid’s plugin:
Import the generated CSS once in the application entry so every route has it:
The HTML entry must have a matching mount element and load src/main.tsx:
Use the App from the installation example to check the button’s appearance. The preset’s default theme does not need MoraineProvider. With TypeScript, add vite/client to your compiler types so the virtual CSS import resolves.
Scanning component classes#
The glob ./node_modules/moraine/dist/**/*.{mjs,jsx} scans the whole moraine/dist directory. The preset does not configure scanning paths for your application.
Filesystem scanning reads these classes regardless of which modules Vite has requested:
- Keep both the application and package globs, including lazy-loaded route files and
.tsfiles that contain class maps. - In
@subf/unocss/vite, thepipeline.includefilter also applies to filesystem extraction, and UnoCSS’s default filter omits.mjsand.ts. - Replacing
pipeline.includeoverrides the default filter, so include every extension your application uses. See UnoCSS’s extraction guide.
Filesystem globs are relative to Vite’s root. The examples assume src/ and node_modules/moraine live under that root. Adjust the globs if you set a different Vite root, keep routes outside src/, or use a workspace with Moraine installed at the repository root. Add your Markdown or MDX directories when they contain application classes.
Verification and troubleshooting#
Check the installation button in each verification scenario: its background, padding, and border radius. A working click handler does not verify CSS generation.
If styles are missing:
- Confirm
virtual:uno.cssis imported in the application entry and the UnoCSS plugin runs before the Solid plugin. - Confirm both the Wind preset and
presetMoraine()are enabled. With Wind3, passwind3: true. - Check that the filesystem globs match the installed Moraine distribution and every application source directory, including lazy routes.
- Check that
pipeline.includeallows those file extensions and that no custom exclusion filter rejects the files. - Inspect a missing class in browser DevTools:
- A missing CSS rule points to extraction or utility configuration.
- An existing rule with an unresolved
--primaryor another theme variable points to theme configuration. WiththemeDefaults: false, the application must provide its theme variables.
For a suspected dependency-cache issue, stop the server and run your Vite dev command with --force (for example pnpm run dev --force), or remove Vite’s cacheDir (default node_modules/.vite) before restarting. Temporarily disable browser caching while diagnosing cached dependency requests. See Vite’s dependency caching guide.
After you correct the scan configuration, restart again with the cache retained. Clearing the cache is a diagnostic step, not part of normal startup. Restart after upgrading Moraine so UnoCSS scans its published files again.
With lazy routes, keep the CSS import in the application entry rather than relying on another route to load styles first. Filesystem scanning discovers static classes before a route loads, but cannot infer dynamic runtime strings such as bg-${color}. Use complete static class maps or an explicit UnoCSS safelist for dynamically selected classes.
Preset options#
presetMoraine() provides Moraine’s utility tokens, state variants, opaque neutral light and dark colors as RGB values, a translucent backdrop, default shadows, and base values for radius, font size, and spacing:
- Dark
borderandinputusergb(35, 35, 35)andrgb(47, 47, 47)so boundaries remain consistent across parent surfaces. - The status colors (
info,success,warning,danger) use Moraine’s tuned status palette. - The default theme selectors are
:rootand.dark. - Configure single-value tokens at the top level, and place colors, shadows, and
colorSchemeinside namedoverrideentries.
The default semantic shadows match the Tailwind values from the shadcn/ui neutral theme: surface → sm, overlay → md, and input → xs. The preset emits --shadow-surface, --shadow-overlay, and --shadow-input at :root; dark mode inherits them unless override.dark.shadows replaces them.
Native size utilities such as shadow-xs keep the CSS engine’s own values. Set themeDefaults: false to omit the built-in colors and semantic shadows while keeping explicit overrides.
| Option | Default | Behavior |
|---|---|---|
wind3 |
false |
Enables Wind3 theme mappings and semantic color alpha compatibility. Native numeric spacing and sizes remain unchanged. |
themeDefaults |
true |
Emits neutral light/dark colors and color schemes, default shadows, and HTML background/text styles. Set false when your CSS defines the theme. |
override |
omitted | Overrides the built-in neutral light and dark colors or adds named themes. |
override.<name>.colorScheme |
light for the built-in light theme; dark for dark; omitted for custom themes |
Accepts light or dark only. Emits color-scheme on the theme selector; explicit values still apply with themeDefaults: false. |
mix |
{ hover: 6, active: 10, ink: 25, soft: 12, border: 20 } |
Sets the color-mix percentages for hover, active, ink, soft, and border states. A number from 0 to 100 becomes a percentage; a string is used as written. Each configured value is written as a --mo-mix-* variable. Overridable per theme via override.<name>.mix. |
radius |
0.625rem |
Base radius written to --radius at :root; override per theme when needed. |
fontSize |
1rem |
Base font size written to --font-size at :root; used by Wind4 typography rules. |
spacing |
0.25rem |
Base spacing unit written to --spacing at :root. |
sidebarWidth |
omitted | Writes an explicit global --sidebar-width at :root; overridable per theme. Sidebar supplies its own fallback when unset. |
Theme tokens#
Inside each named override.<name> entry, configure colors, shadows, dimensions, and color scheme:
- Grouped colors (
primary,secondary,neutral,muted,accent,card,popover,danger,info,success,warning): A string is shorthand for{ base: value }. Pass an object to overrideforeground,hover,active,ink,soft, orborderindividually. - Single-value colors (
background,foreground,border,input,control,backdrop,ring): Accept CSS color strings only.controlsets form field fills independently of--inputboundaries and parent surfaces. - Semantic shadows:
shadowsacceptssurface,overlay, andinput, which emit--shadow-surface,--shadow-overlay, and--shadow-input; see Backdrop and Semantic Shadows. - Dimensions:
radius,fontSize,spacing, andsidebarWidthcan be set at the top level or overridden per theme. - Typography and custom properties: Configure font families in CSS through
--font-sans,--font-mono, and--font-serif(see Typography and Spacing), and declare any other custom properties in your stylesheet.
light and dark target :root and .dark by default. Any other theme name defaults to [data-theme="name"]; set selector on an entry to customize its CSS selector. The preset emits default light tokens first, then dark tokens, then custom themes in declaration order. Light and dark overrides merge with their built-in defaults, while custom themes inherit unspecified variables through the CSS cascade.
The built-in light and dark themes emit color-scheme: light and color-scheme: dark so native browser controls match the theme. colorScheme ('light' | 'dark') is configured per theme on override.<name> and writes the native CSS color-scheme property rather than a CSS variable. themeDefaults: false omits the default color schemes while keeping explicit colorScheme values.
See Moraine-specific Variables for the full list of form surface, backdrop, shadow, interaction, typography, sidebar, and animation variables.
Semantic color alpha modifiers such as bg-primary/20 use color-mix(in srgb, …) in supported browsers. presetWind4 supports color-mix natively, and wind3: true enables the same alpha syntax in Wind3.
Wind3 compatibility#
Use presetMoraine({ wind3: true }) with presetWind3(). This enables Wind3 semantic token mappings, color alpha compatibility, the forced-colors: variant, and forced-color-adjust-* utilities. Numeric spacing and size utilities keep Wind3’s native values, so changing --spacing does not scale them; use explicit variable utilities such as p-(--app-padding) for runtime spacing changes.
Typography and border radius configuration differs between Wind3 and Wind4:
- Wind3:
--font-sizedoes not scale typography. Customize font sizes viatheme.fontSizeand named radii viatheme.borderRadius. - Wind4: Local
--font-sizeand--radiusvariables scale the default typography and radius tokens automatically. Customize them viatheme.textandtheme.radius.
Explicit UnoCSS theme values take precedence in both modes. Use leading-* to adjust line height independently of font size.
Font families#
Configure font families through UnoCSS’s theme object, separately from presetMoraine() options. Wind4 uses theme.font; Wind3 uses theme.fontFamily:
For Wind3, use presetWind3() with presetMoraine({ wind3: true }) and place the same entries under theme.fontFamily.
Explicit theme values override Moraine’s CSS variable references. To keep runtime font switching via CSS variables, set sans: 'var(--font-sans)' and define --font-sans in your stylesheet. Load custom font files separately.
Surface states and tone derivation#
Moraine separates semantic roles into surfaces (background, card, popover, muted, accent) and tones (primary, secondary, neutral, danger, info, success, warning), deriving their hover, active, ink, soft, and border colors with color-mix:
mixsets the mixing percentages globally.override.<name>.mixoverrides those percentages for a specific theme.- An explicit
colors.<tone>.hover,active,ink,soft, orbordervalue bypassescolor-mixfor that channel.
See State Colors and Tone Ink Derivation for the 3-tier fallback chain.
The tone-<color> utility publishes a color group’s channels (--mo-tone, --mo-tone-foreground, --mo-tone-hover, and so on) on an element, and descendants read them with bg-tone, text-tone-ink, hover:bg-tone-hover, and related utilities.
When your CSS supplies its own color palette, disable the built-in palette and define Moraine’s --control variable:
themeDefaults: false omits --control unless you configure control in override. A standard shadcn/ui palette does not define --control; see Form control surface. With themeDefaults: false, the preset still emits default --radius, --font-size, and --spacing values, which your CSS can override.