Tailwind CSS
Configure the Moraine Tailwind CSS plugin for Tailwind CSS v4, scanner paths, and custom utilities.
The moraine/tailwind entry exports a Tailwind CSS plugin. It maps Moraine tokens to CSS variables and registers semantic z-index utilities, keyframe animations, parametric transform utilities, tone utilities, and data-* / aria-* state variants.
Tailwind CSS v4#
In an existing Solid/Vite project, install Moraine, Tailwind, and Tailwind’s Vite integration:
Register Moraine with the @plugin directive and scan its published distribution files with @source:
Import ./index.css in src/main.tsx and define the theme variables described below. Keep the import in the application entry so the stylesheet loads when a user opens any route directly. See Tailwind’s Vite integration guide for the build-tool setup.
The @source path directive#
Tailwind CSS v4 ignores node_modules during automatic source detection. The Moraine plugin registers utility rules and variants, but not component files as sources. Use @source even when the plugin is registered. See Tailwind’s source detection guide.
Scan the full moraine/dist directory, and note the following requirements:
- Path resolution:
@sourcepaths are filesystem paths relative to the stylesheet, not package imports. Point to the publisheddistfolder (for example,'../node_modules/moraine/dist'forsrc/index.css). - Monorepos and workspaces: If
moraineis hoisted to a rootnode_modulesdirectory in a pnpm or npm workspace, adjust the relative path to point to the repository root:
Tailwind discovers static classes by scanning files, whether or not a lazy route has loaded. Cover route directories with automatic source detection or explicit @source entries. If you disable automatic detection with source(none), also register your application sources. These paths are relative to the stylesheet; automatic detection uses the working directory unless you configure a base path.
Theme variables#
Theme variables and page background/text styles belong in your stylesheet. The plugin registers utilities and variants, but does not emit theme color values.
You can start from a shadcn/ui theme palette, then add Moraine’s --control surface and semantic shadows:
Key role tokens:
- Form control surface (
--control):bg-controlstyles outline fields, unchecked choices, and upload surfaces, whileborder-inputstyles field boundaries, neutral tracks, and separators.controluses field text colors, has no separate foreground or state family, and supports alpha utilities such asbg-control/30. See Form control surface. - Surface and tone states: Surface interaction utilities (
hover:bg-accent-hover,active:bg-accent-active) mix the surface toward its foreground viacolor-mix(in oklch, …)and fall back to the base surface color elsewhere. Tones expose derived--<tone>-inktext colors and--<tone>-softtranslucent washes that composite over the local surface. - Backdrop and semantic shadows:
bg-backdropreads--backdrop(falling back to black at 32% opacity). Component shadows useshadow-surface,shadow-overlay, andshadow-input(--shadow-surface,--shadow-overlay,--shadow-input). Set any role token tononeto remove its elevation. Native size utilities such asshadow-xsremain governed by Tailwind’s own theme. See Backdrop and Semantic Shadows. - Sidebar width (
--sidebar-width): Optional global variable on:rootfor the desktop sidebar width; falls back toclamp(14rem, 25%, 20rem)when unset.
Injected utilities and variants#
The plugin registers the following utilities and variants with Tailwind v4:
Parametric transform utilities#
Combine these with animate-mo-enter and animate-mo-exit to customize motion:
- Opacity:
enter-opacity-<percent>,exit-opacity-<percent> - Scale:
enter-scale-<percent>,exit-scale-<percent> - Translate:
enter-translate-x-<num>,enter-translate-y-<num>,exit-translate-x-<num>,exit-translate-y-<num> - Rotate:
enter-rotate-<deg>,exit-rotate-<deg>
See the Animations guide for details and interactive specimens.
Semantic z-index utilities#
z-base(1)z-raised(2)z-control(3)z-sticky(10)z-resize(20)z-overlay(40)z-floating(50)
Tone and accent utilities#
tone-<color>publishes a color group’s channels (--mo-tone,--mo-tone-foreground,--mo-tone-hover, and so on) on an element. Descendants read them withbg-tone,text-tone-ink,hover:bg-tone-hover, and similar utilities.accent-scopeandaccent-fg-<color>let a host publish--mo-accent-fg(usually underhover:orfocus-within:) so descendants switch to the accent foreground. Without it,accent-fg-<color>falls back to the named color.
State attribute variants#
Target component DOM states with these utility prefixes:
- Data attributes: A fixed set of component state names, including
data-active:,data-checked:,data-closed:,data-disabled:,data-expanded:,data-focused:,data-hidden:,data-highlighted:,data-invalid:,data-loading:,data-open:,data-pressed:,data-selected:, anddata-submitting:. - ARIA attributes:
aria-busy:,aria-checked:,aria-disabled:,aria-expanded:,aria-hidden:,aria-invalid:,aria-modal:,aria-pressed:,aria-readonly:,aria-required:,aria-selected:
Design tokens and CSS variables#
The plugin maps utility classes such as bg-primary, text-foreground, and rounded-lg to CSS variables. Define your color palette and dimensions in your application stylesheet as described in the Design guide.
The default text-tiny through text-9xl scale reads the local --font-size, and named radius utilities read --radius. Explicit Tailwind theme values can replace these mappings. See Typography and spacing for the differences between Tailwind, UnoCSS Wind3, and UnoCSS Wind4.
Troubleshooting#
Check the installation button in each verification scenario.
- No utility styles: Confirm Tailwind’s build integration runs and your application entry imports its stylesheet.
- Application classes work, but Moraine classes are missing: Confirm
@plugin 'moraine/tailwind'is loaded and@sourcepoints to the installed distribution. Registering a plugin does not scan a dependency. - Rules exist, but colors, radius, or shadows are missing: Check the referenced CSS variables and their scope. Unlike
presetMoraine()with default options, the Tailwind plugin does not emit a complete default theme. NeitherMoraineProvidernor the optionalmoraine/icon.cssreplaces theme variables or scanning. - Classes from a lazy route are missing: Check source coverage and keep the stylesheet import in the application entry. Correctly registered sources do not require navigating through the home page first.
- Dynamically constructed classes are missing: Use complete static class maps. Tailwind cannot infer classes such as
bg-${color}. In v4, include extra classes explicitly with@source inline()on versions that support it. The legacy JavaScriptsafelistoption is not supported in v4. See Tailwind’s safelisting guide.
If clearing Vite’s dependency cache changes the symptom, recheck the imported stylesheet, registered sources, and theme configuration, then verify a restart with the cache retained. Clearing the cache does not replace @source and is not part of normal setup.