Preline Theme Generator
This file is for the AGENT (LLM) only — not end users.
Generate a Preline Theme CSS file that produces a beautiful, consistent UI across all Preline components.
Docs
- to (detailed workflow guidance)
- (mood, hue, neutral mapping, OKLCH rules)
docs/validation-checklist.md
Agent workflow (FOLLOW THIS)
When user requests a theme, the agent MUST:
Step 1: Interpret user request
Parse the natural language description and determine the config inputs. See
and
.
Step 2: Detect themes folder
Find where existing themes are stored in the user's project:
bash
# Look for existing theme.css to find the themes folder
find . -name "theme.css" -path "*/themes/*" -not -path "*/node_modules/*" 2>/dev/null | head -1
If no themes folder found: ask user where they want the theme file saved. See
.
Step 3: Create temp config file (AUTO-RUN, NO PROMPT)
Write a JSON config. This must run silently without user approval.
bash
echo '{"name":"<theme-name>","hue":<hue>,"style":"<style>","useCustomDarkGray":<true|false>,"tailwindGray":"<gray>"}' > /tmp/preline-theme-config.json
Step 4: Run the generator + cleanup (AUTO-RUN, NO PROMPT)
Run generator and immediately delete temp file in a single command chain. This must run silently without user approval.
Option A (preferred) - use npx if preline is installed:
bash
npx preline-theme-generator /tmp/preline-theme-config.json <themes-folder>/<theme-name>.css && rm /tmp/preline-theme-config.json
Option B - find and run the script directly:
bash
node $(find . -path "*/preline/skills/theme-generator/scripts/generate-theme.js" 2>/dev/null | head -1) /tmp/preline-theme-config.json <themes-folder>/<theme-name>.css && rm /tmp/preline-theme-config.json
Option C - if script location is known (e.g., in node_modules):
bash
node node_modules/preline/skills/theme-generator/scripts/generate-theme.js /tmp/preline-theme-config.json <themes-folder>/<theme-name>.css && rm /tmp/preline-theme-config.json
Step 5: Confirm to user
Tell user the theme was created and show enable snippet:
css
/* In your main CSS file */
@import "./themes/<theme-name>.css";
html
<!-- On HTML element -->
<html data-theme="theme-<theme-name>">
See
and
for response examples.
Generated themes include
- Coherent light + dark modes
- Safe to ship (valid CSS, correct selectors)
- No HTML class changes required (only + optional )
- Custom color palettes in
@theme theme-<name> inline { }
block
Example prompts
Simple:
"Create a sunset theme"
Descriptive:
"Create a theme that feels like a cozy coffee shop — warm browns, cream backgrounds, inviting and calm"
Specific:
"Generate a cyberpunk theme with neon cyan accents on dark surfaces"
Brand-focused:
"Create a theme matching this brand color #2F6BFF — professional, high-clarity SaaS feel"
RULES (ALL MUST BE FOLLOWED)
Rule 1 — Do not modify the shipped base theme
- Never change . Always generate a separate theme file.
Rule 2 — Theme file MUST include imports in this exact order
Every generated theme file MUST begin with:
Rule 3 — Theme scoping block placement
Every theme file MUST include a scoping block after imports:
css
@theme theme-<name> inline {
/* Theme scoping - custom palettes only */
}
What goes INSIDE this block:
- Custom color palettes (soft grays, brand colors) — these create Tailwind utilities
- Example:
--color-<name>-50: oklch(98% 0.003 <hue>);
through
What goes OUTSIDE (in selector blocks):
- All semantic token overrides (, , , etc.)
- Tailwind core mappings are owned by the shipped base theme only
See
for palette construction details and examples.
Rule 4 — No HTML utility class edits required
- Theme must NOT require users to change Tailwind utility classes in HTML.
- Theme activation must work using ONLY:
- CSS imports
data-theme="theme-<name>"
- Dark mode may use if the project uses it; do not introduce new conventions.
Rule 5 — Use exact, required theme selectors
Light mode token overrides MUST be under:
css
:root[data-theme="theme-<name>"],
[data-theme="theme-<name>"] { ... }
Dark mode overrides MUST be theme-scoped and use:
css
[data-theme="theme-<name>"].dark { ... }
Rule 6 — Full-theme mode: comprehensive token coverage is REQUIRED
Because this generator is full-theme mode, output MUST define a comprehensive set of token values so the theme looks complete and intentional.
At minimum, the theme MUST define:
6.1 Global surfaces + text
6.2 Borders (full scale)
6.3 Primary ramp (full) + primary states
- through
- (must be readable)
6.4 Secondary / muted / destructive (at least)
- Include related state/variant tokens if they exist in the base naming system.
6.5 Core component groups for a complete theme feel (prefer explicit values)
Provide explicit values for major component groups so the theme feels cohesive:
- Optionally:
- Charts/maps tokens ONLY if included safely (see Rule 10)
Full-theme output MUST NOT:
- put token definitions inside the block
- invent new mappings that force HTML class edits
Rule 7 — Token naming must match Preline's token system
- Do not invent random token names for Preline components.
- Only introduce new custom tokens if explicitly requested, and keep them isolated and documented in comments.
Rule 8 — Theme-scoped behavior overrides ONLY
If the theme changes behavior (e.g. retro-sharp radii), it MUST be scoped to the theme only.
Allowed:
- Override radius tokens under the theme selector
- Add rules scoped to the theme selector
Not allowed:
- Global overrides without theme scoping
- Any behavior overrides that affect non-theme pages
Rule 9 — Typography tokens are allowed, but font loading is separate by default
If fonts are requested, you MAY set:
inside the theme selector.
Do NOT add Google Fonts
into the theme file unless the user explicitly requests it.
(Font loading typically belongs in the main CSS entry file.)
Rule 10 — Charts/maps compatibility rules
If adjusting chart/map tokens:
- Prefer safe formats where required by libraries.
- Keep any tokens as valid hex values if the ecosystem expects hex.
- Do not force where it may break gradients or third-party rendering.
Rule 11 — Valid CSS is mandatory
- No missing braces
- No invalid selectors
- No broken comments
- No duplicate conflicting selectors
Rule 12 — Output discipline
- First code block must contain ONLY the generated theme CSS.
- Optional second code block may contain ONLY the enable snippet.
- No additional commentary unless explicitly requested.
Required file structure (MUST follow order)
- Imports ()
- Theme scoping block (
@theme theme-<name> inline { }
) — contains custom color palettes only
- Light mode theme selector block (full semantic token set using references)
- Dark mode theme selector block (override only what differs, use for consistency)
- Optional theme-scoped overrides (only if requested)
Additional guidance
- Theme construction details: and
- Palette guidance:
- Validation checklist:
docs/validation-checklist.md
- Token reference: