Grimoire CSS v1.9.0
░ ░ ░
A one-of-a-kind CSS engine that unleashes the magic of your UI

Grimoire CSS is a comprehensive CSS engine crafted in Rust,
focusing on unmatched flexibility, reusable dynamic styling, and optimized performance for every environment. Whether you need filesystem-based CSS generation or pure in-memory processing, Grimoire CSS adapts to your needs without compromising on performance or features.

Everything in Its Place

  1. True CSS engine. Exceptionally powerful and endlessly flexible. Independent and self-sufficient. No bundlers, optimizers, deduplicators, preprocessors or postprocessors required — it outputs final CSS on its own.
  2. Performance. Every part is optimized for maximum efficiency, outperforming any specialized tools. It processes almost 200k classes per second. It is 5× faster and 28× more efficient than TailwindCSS v4.x. All while truly generating CSS.
  3. Universality. The native parser handles any source file without plugins or configuration, running in both filesystem-based and in-memory modes. Available as a standalone binary, a Rust crate, and an npm library.
  4. Intelligent CSS Generation. Respects the CSS cascade and applies necessary vendor prefixes. Uses your .browserslistrc to guarantee target browser support.
  5. Spell and Scroll Systems. Turn CSS into your personal styling language — no arbitrary class names, no hidden abstractions. Write clear property=value Spells, complete with area__, {focus} and effect: modifiers for breakpoints, selectors and pseudo-classes. Bundle them into Scrolls — named, parameterized, inheritable style modules for consistent systems at any scale.
  6. Color Toolkit. A powerful module compliant with CSS Color Module Level 4, enabling precise and high-performance color manipulations. Grimoire CSS also serves as a standalone color toolkit, with its color features available via a public API.
  7. Configuration. Grimoire CSS uses a single JSON configuration file per repository. Its format is straightforward yet robust, supporting monorepos with hundreds of projects or individual configurations — variables, scrolls, generation modes, shared and critical CSS, external files — all out of the box.
  8. Gradual Migration. The Transmutator converts supported class-based CSS rules to Scrolls. Compatible class names can stay in your components. Unsupported names, rules, and source-order dependencies are reported explicitly; keep those styles in CSS files connected through shared.styles while migrating incrementally.

A Spell System

At the heart of Grimoire CSS lies the Spell, the foundational entity of the system. Spell takes a different approach from traditional utility classes, like those you’d find in Tailwind. While utilities in Tailwind feel like slightly enhanced Bootstrap classes, Grimoire CSS takes things to a new level. In Tailwind, you’re expected to memorize arbitrary names like rounded-md for border-radius: 0.375rem - which doesn’t even make things look rounded. And then there’s tracking-tight for letter-spacing: -0.025em. How are you supposed to know that’s related to letter spacing?

Grimoire CSS cuts through that confusion by introducing Spell - an approach that is both simple and infinitely flexible. At its core, a Spell is just a CSS declaration, written in a format everyone understands: property=value. For example, border-radius: 0.375rem in Grimoire CSS becomes border-radius=0.375rem. If you prefer something shorter, bd-rad=0.375rem works too, or even bd-rad=.375rem (yes, Grimoire CSS respects CSS’s own shorthand capabilities). Unlike pre-baked utility classes, Spells follow the natural structure of CSS: property: value becomes component=target. If you don’t know any shorthands yet, you can always write out full components (each full component directly maps to its corresponding CSS property) and then run the shorten command to convert all full components in your files (that defined in config) into their shorthand forms. Easy as it should be!

This isn’t just another syntax. It’s the whole system reimagined. You’re free to write any value in the target, whether it’s custom units, functions, or even complex animations. Everything CSS supports is fair game, and all you need to do is escape spaces with underscores (_). That’s it. Of course, we didn’t stop at the basics. Spells also introduce optional enhancements: area, focus, and effects, which give you deeper control over media queries, pseudo-classes, attributes, and more.

The entire Spell system is built on clarity and explicitness. There are no magical, arbitrary strings for targets like you find in other systems. And we don’t compromise on clarity for the sake of brevity. Targets are full, valid CSS values - because that’s how it should be. Components mirror actual CSS properties, but they can be shortened if you want. In this way, Grimoire CSS is both a CSS declaration and a methodology. It’s so powerful because every Spell is valid CSS - there’s no abstraction that gets in the way of what you need to achieve.

So, why call it a Spell? Because, like magic, it’s composed of multiple elements: area, focus, effect, component, and target. And each of these pieces works together to create something far greater than the sum of its parts. With Grimoire CSS, you’re not just writing styles - you’re casting spells. The name Grimoire comes from ancient magical texts. Just as those books hold the knowledge to perform spells, Grimoire CSS provides you the knowledge and tools to perform CSS magic - without relying on pre-baked solutions. You’re in full control.

Recap

Scroll: Crafting Reusable, Dynamic CSS with Infinite Flexibility

A Scroll is like a Spell, but with one crucial difference - it’s something you build from scratch. Think of it as a customized collection of styles, bundled into one reusable class. Sometimes, you need to combine multiple styles into a single class for consistency, reusability, or just to make your life easier. With Scroll, you can do just that. Combine spells, give your new creation a name, and you’ve got a Scroll ready to use across your projects.

And here’s the best part: everything you love about Spells works seamlessly with Scrolls too - area, focus, effect, and even target. But there’s even more: when you define a Scroll, you can introduce variables to make your styles dynamic. Just use the $ symbol, and the target becomes a placeholder, waiting for the actual value to be filled in. Want to create a button class that accepts variable values? No problem. Here’s an example:

"scrolls": [
  {
    "name": "btn",
    "spells": [
      "padding=6px",
      "border-radius=$",
      "align-items=center",
      "background=none",
      "background-color=$",
      "cursor=pointer",
      "hover:background-color=$",
      "active:background-color=$",
      "xl__min-width=32px",
      "xl__padding=10px",
      "xl__hover:font-weight=bold"
    ]
  }
]

This btn scroll expects four target values, and if you pass fewer or more, Grimoire CSS will kindly let you know. The targets are applied in order, giving you incredible flexibility. But we’re not done yet.

Inheritance with Scrolls: The Power of Composition

One of the most exciting aspects of Scrolls is inheritance. Yes, you can extend a Scroll with another Scroll. Combine and compose them endlessly to create complex, reusable styles. Let’s take a look:

"scrolls": [
  {
    "name": "btn",
    "spells": [
      "padding=6px",
      "border-radius=$",
      "align-items=center",
      "background=none",
      "background-color=$",
      "cursor=pointer",
      "hover:background-color=$",
      "active:background-color=$",
      "xl__min-width=32px",
      "xl__padding=10px",
      "xl__hover:font-weight=bold"
    ]
  },
  {
    "name": "danger-btn",
    "extends": [
      "btn"
    ],
    "spells": [
      "hover:g-anim=vibrate-3",
      "animation-iteration-count=infinite",
      "color=white"
    ]
  },
  {
    "name": "danger-btn-rnd",
    "extends": [
      "danger-btn",
      "round"
    ],
    "spells": []
  },
  {
    "name": "round",
    "spells": [
        "border-radius=999999px",
        "height=$",
        "width=$"
    ]
  }
]

In this example, danger-btn extends btn, meaning it inherits all of btn’s spells plus its own. So, danger-btn.spells will look like btn.spells + danger-btn.spells, with the parent scroll’s styles taking priority at the top.

But the fun doesn’t stop there - danger-btn-rnd extends both danger-btn and round. This means that danger-btn-rnd.spells equals btn.spells + danger-btn.spells + round.spells, combined in the correct order. And yes, the order matters. This layered inheritance allows you to build complex style structures effortlessly.

Why Scrolls Matter: Unlimited Possibilities

The real magic of Scrolls lies in their unlimited possibilities. You can chain styles together, extend them endlessly, and define variables as placeholders to create flexible, reusable patterns across your entire project. With Scrolls, Grimoire CSS goes far beyond being Yet Another CSS Framework. In fact, you could even recreate the entire structure of Tailwind or Bootstrap using nothing but the flexibility of Spells and Scrolls.

It’s pure, beautiful madness - without limits.

Variables and Built-in Functions: Total Control Over Styles and Sizes

Grimoire CSS allows you to define your own variables within its settings, making your styling even more dynamic and customizable. Unlike custom properties, these variables don’t compile and remain in your settings and are only compiled when used - keeping your CSS clean and efficient.

How to Use Variables

You can define any value as a variable - font sizes, colors, dimensions, anything. To reference them in your styles, just add the $ symbol before the variable name (you’ll remember this from the Scroll section). Here’s how you define and use a variable:

Defining a Variable

{
  "variables": {
    "hero-fs": "42px"
  }
}

Using the Variable

<h1 class="font-size=$hero-fs">Hero text</h1>

In this example, the hero-fs variable holds the value 42px, which is then applied to the font-size of the <h1> element. Variables in Grimoire CSS offer a simple and effective way to maintain consistency across your styles, while keeping your code flexible and DRY.

Built-in Areas: Responsive Design, Simplified

Grimoire CSS follows a mobile-first approach and comes with built-in responsive areas, including sm, md, lg, xl, and 2xl. When you define a spell with one of these areas, like md__width=100px, the spell will apply only when the screen width is equal to or greater than the specified area.

For example, md__width=100px is equivalent to this media query: (width>=768px)__width=100px.

Of course, you’re not limited to the built-in areas. You can define your own media queries just as easily, like this:

(width>666px)__width=100px

With these areas, you have full control over your responsive design, but without the hassle of constantly writing and rewriting media queries.

Adaptive Size Functions: mrs and mfs

Grimoire CSS takes responsive design even further with built-in functions like mrs (Make Responsive Size) and mfs (Make Fluid Size). These functions allow you to adapt font sizes, widths, and more based on the viewport size.

mrs: Make Responsive Size

This function dynamically adjusts the size of an element between a minimum and maximum value, depending on the viewport width. Here are the arguments:

Example Usage of mrs

<p class="font-size=mrs(12px_36px_480px_1280px)">
  Font size of this text will dynamically change based on the screen size
</p>

In this example, the font size will automatically adjust between 12px and 36px, depending on the screen size, with fluid adjustments in between. This makes responsive design not only easier but more precise, without the need for complex calculations or multiple breakpoints.

mfs: Make Fluid Size – Creates fully fluid sizes without media queries for seamless scaling

Here are the arguments:

Example Usage of mfs

<p class="font-size=mfs(12px_36px)">
  Font size smoothly scales between 12px and 36px based on the viewport size.
</p>

The Power of Grimoire’s Variables and Functions

With Grimoire CSS, you don’t just write styles - you take control of them. By leveraging variables, responsive areas, and adaptive size functions, you can make your CSS dynamic, scalable, and ready for any device or screen size. It’s flexibility without the fuss, and it’s all built right in.

Predefined Scrolls and Built-In Animations: Flexibility at Your Fingertips

Grimoire CSS doesn’t just give you the tools to build powerful styles from scratch - it also comes with a set of predefined scrolls to help you get started right away. All predefined scrolls follow the same convention: they begin with the prefix g-. This makes it easy to distinguish built-in scrolls from the ones you define yourself.

Built-In Animations: Ready When You Are

Grimoire CSS comes loaded with hundreds of built-in animations (700+ at the moment). These animations are lightweight and efficient - they are only compiled if you actually use them. To trigger one, simply use its name in either the animation-name or animation CSS rule. But Grimoire CSS doesn’t stop at just applying animations; it also simplifies the process of adding associated rules.

For example, the predefined scroll g-anim allows you to apply an animation and its associated rules at the same time. Here, g- is the prefix, and anim is a short version of the spell animation. With this scroll, you can quickly inject an animation along with the necessary rules - saving time and keeping your styles clean and organized.

Create Your Own Animations

Even though Grimoire CSS comes packed with animations, it also gives you the power to add your own, seamlessly integrating them into your projects. It’s as simple as creating a new subfolder called animation inside the grimoire folder, then adding your custom CSS file using the format <name-of-animation>.css.

Within that file, you define your animation using @keyframes, along with any custom styles. You can also use the class placeholder GRIMOIRE_CSS_ANIMATION to add specific styles tied to the animation itself. Let’s take a look at an example with a custom pulse animation:

@keyframes pulse {
  from {
    transform: scale3d(1, 1, 1);
  }

  50% {
    transform: scale3d(1.05, 1.05, 1.05);
  }

  to {
    transform: scale3d(1, 1, 1);
  }
}

.GRIMOIRE_CSS_ANIMATION {
  animation-name: pulse;
  animation-timing-function: ease-in-out;
}

In this example, you’ve defined the pulse animation and set it up with ease using the GRIMOIRE_CSS_ANIMATION placeholder. Once this file is in your project, you can invoke the pulse animation as easily as any built-in animation, giving you complete control over custom animations.

External Scrolls & Variables

In addition to defining scrolls and variables within grimoire.config.json, Grimoire CSS allows you to extend your configuration with external JSON files for scrolls and variables. These external JSON files follow the same structure as their corresponding properties in the config file. These files should be stored alongside your main configuration file.

Before generating CSS, Grimoire CSS checks for any external scrolls or variables and merges them into the main config (with the main config taking priority, so external scrolls/variables won’t override your primary configuration settings). This adds flexibility, scalability, and convenience to your workflow.

This feature enables sharing your scrolls/spells independently from your main configuration, as well as using those created by others. For example, you can use the Tailwind CSS implementation via external scrolls. More information about where to share and find scrolls, variables, or complete configurations will be detailed below.

Language-Agnostic Parser: Extracting Spells from Any File, Any Format

Grimoire CSS isn’t just tied to traditional CSS, JavaScript, or HTML files. The beauty of its language-agnostic parser is that it can parse spells from any file or extension. Whether you’re working with .html, .tsx, .mdx, or something else entirely, it can handle it.

This means you’re not limited by file types or formats - you define the inputPaths, and Grimoire takes care of the rest. Whether your project is built with React, Vue, or something entirely different, it seamlessly integrates and extracts the styles you need.

Spells in Plain Text with Template Syntax

If you want to use spells outside the traditional class or className attributes, Grimoire CSS provides a clever solution with its template syntax: g!<spell>;. This syntax lets you wrap your spell in a template, enabling the parser to collect spells from any text-based content.

Template syntax works for scrolls too, by the same rules as spells (including prefixes and modifiers). For example: g!complex-card=120px_red_100px;.

Let’s say you have both a classic spell and a templated spell that are essentially the same. Don’t worry - Grimoire CSS is smart enough to combine them into one, as long as it doesn’t affect the CSS cascade. The result? Clean, efficient CSS output like this:

.classic,
.templated {
  /* CSS declaration */
}

Template syntax also supports multiple spells in a single template using the & symbol as a spells separator: g!color=violet&display=flex;. This enables CSS-in-JS–like scenarios in absolutely any files.

This flexibility means you can integrate Grimoire CSS in non-traditional environments, using it across various file types and even in plain text. It’s not just tied to the web - it’s ready for any project, anywhere.

CSS Optimization: Minification, Vendor Prefixes, and Deduplication - All with CSS Cascade in Mind

Grimoire CSS doesn’t just help you manage your styles - it ensures that only the CSS you actually need is generated. No duplicates, no wasted space. Whether it’s shared across multiple projects or inlined for critical loading, Grimoire makes sure your CSS is lean, efficient, and optimized for performance.

Grimoire CSS takes optimization seriously. It generates only the CSS that’s actually used, and it monitors for duplicates right from the start, ensuring no unnecessary styles sneak through. This happens at the very early stages of generation, so by the time the process finishes, you’ve got a lean, clean stylesheet.

But it doesn’t stop there. Just take a look:

All of this happens while preserving the CSS cascade - no unintentional overwrites, no broken styles. Just clean, optimized CSS that’s ready for any environment.

Professional-Grade Color Toolkit

Grimoire CSS introduces a comprehensive suite of built-in color manipulation functions, compliant with the CSS Color Module Level 4 specification. These functions enable precise and dynamic color transformations:

Example Usage

Usage Rules:

  1. All arguments are positional, and any optional arguments can be omitted if they are not being changed.
  2. Do not include %, deg, or other units in the values - Grimoire handles these internally.
<div class="bg=g-grayscale(#ff0000)">Grayscale Red Background</div>

<div class="bg=g-complement(#00ff00)">Complementary Green Background</div>

<div class="bg=g-invert(#123456)">Fully Inverted Background</div>
<div class="bg=g-invert(#123456_50)">Partially Inverted Background</div>

<div class="bg=g-mix(#ff0000_#0000ff_50)">Purple Background</div>

<div class="bg=g-adjust-hue(#ffcc00_45)">Hue Adjusted Background</div>

<div class="bg=g-adjust-color(#123456_0_0_12)">Adjust Blue Component</div>
<div class="bg=g-adjust-color(#123456_0_0_12_5)">Adjust Blue and Saturation</div>

<div class="bg=g-change-color(#123456_255_0)">Set Red and Green Components</div>
<div class="bg=g-change-color(#123456_0_0_0_180)">Set Hue Only</div>

<div class="bg=g-scale-color(#123456_10_-10)">Scale Red Up, Green Down</div>
<div class="bg=g-scale-color(#123456_0_0_0_20)">Scale Saturation Up</div>

<div class="bg=g-rgba(#123456_0.5)">Half Transparent Background</div>

<div class="bg=g-lighten(#123456_10)">Lightened Background</div>

<div class="bg=g-darken(#123456_10)">Darkened Background</div>

<div class="bg=g-saturate(#123456_20)">More Saturated Background</div>

<div class="bg=g-desaturate(#123456_20)">Less Saturated Background</div>

<div class="bg=g-opacify(#123456_0.2)">More Opaque Background</div>

<div class="bg=g-transparentize(#123456_0.2)">More Transparent Background</div>

These functions provide developers with an extensive toolkit for creating vibrant, dynamic, and flexible styles with ease.

Projects

In Grimoire CSS, managing your projects is as flexible as the spells themselves. You define exactly which files need to be parsed (inputPaths, supporting glob patterns) and specify where the built CSS should go (outputDirPath).

You also have two powerful options for compiling your CSS:

  1. Single Output File: Where all parsed spells from various files are compiled into a single CSS file.
  2. Individual Output Files: Where each input file has its own corresponding CSS file.

For single output mode, you’ll just need to define the name of the final CSS file with singleOutputFileName. The flexibility here allows you to control the output method depending on your project’s needs. Every project configuration contains a name property and can include as many projects as you want. Whether you’re building a single-page application (SPA) or managing multiple projects, Grimoire CSS has you covered.

In essence, the projects section of your config is a list of projects, each with its own unique input and output settings. Here’s how that might look:

"projects": [
  {
    "projectName": "personal",
    "inputPaths": [
      "personal/src/*.tsx"
    ],
    "outputDirPath": "personal",
    "singleOutputFileName": "personal.build.css"
  },
  {
    "projectName": "blog",
    "inputPaths": [
      "blog/*.html"
    ],
    "outputDirPath": "grimoire/build/blog"
  },
  {
    "projectName": "mix",
    "inputPaths": [
      "about/hero.tsx",
      "blog/index.html"
    ],
    "outputDirPath": "grimoire/build/mix",
    "singleOutputFileName": "mix.css"
  }
]

Projects on Your Terms

Grimoire CSS gives you full control over how you manage and compile your styles. You can configure projects for different output strategies depending on whether you’re building large, single-page applications or static sites with multiple pages. The flexibility to switch between single or multiple output files means you’re never locked into one approach. Grimoire adapts to your needs, not the other way around.

Locking

Grimoire CSS supports a locking mechanism for efficient builds. By enabling the lock option in grimoire.config.json, you can automatically track and clean up outdated built files

{
  "projects": [
    {
      "projectName": "main",
      "inputPaths": []
    }
  ],
  "lock": true
}

Shared and Critical CSS: Optimizing Your Styles for Maximum Efficiency

Grimoire CSS makes it easy to define shared and critical CSS alongside your project-specific styles, allowing you to optimize how styles are applied across your entire application.

Shared CSS: One File, Multiple Uses

Shared CSS is exactly what it sounds like - a set of styles that you can build into a separate file and reuse across multiple projects or pages in your application. By defining shared styles, you ensure consistency and reduce repetition, improving performance and maintainability.

Critical CSS: Inline for Faster Rendering

Critical CSS goes a step further. It automatically inlines essential styles directly into your HTML files, ensuring that key styles are loaded instantly. And here’s the clever part: if some spells are already used in your components or files, Grimoire won’t regenerate them - because they’re now part of your critical CSS. No duplicates, no unnecessary bloat - just efficient, fast-loading styles.

How It Works

Both the shared and critical sections of the config are similar in structure. Each has:

For shared CSS, you’ll define an outputPath - the file where your shared styles will be stored. For critical CSS, you’ll define fileToInlinePaths - a list of HTML files (or glob patterns) where these essential styles should be inlined.

Let’s take a look at some examples:

Defining Custom Properties

In the cssCustomProperties section, you can define custom properties and their key-value pairs for any DOM elements in your app. Here are the key parts of this configuration:

  1. element: The optional DOM element associated with the CSS variable (e.g., tag, class, id, or even :root).
  2. dataParam: The parameter name used in your CSS configuration.
  3. dataValue: The corresponding value for that parameter.
  4. cssVariables: A set of CSS variables and their values that will be applied to the element.

Here’s how this might look in JSON:

"cssCustomProperties": [
  {
    "element": "body",
    "dataParam": "theme",
    "dataValue": "light",
    "cssVariables": {
      "base-bg-clr": "white"
    }
  },
  {
    "element": "body",
    "dataParam": "theme",
    "dataValue": "dark",
    "cssVariables": {
      "base-bg-clr": "black"
    }
  }
]

This structure allows you to define theme-specific variables, making it easier to maintain consistency across your application.

Real-World Example

Here’s a complete example of how you might configure shared and critical CSS in Grimoire:

"shared": [
  {
    "cssCustomProperties": [],
    "outputPath": "shared.css",
    "styles": [
      "font-size=20px"
    ]
  }
],
"critical": [
  {
    "fileToInlinePaths": [
      "about/*.html",
      "blog/*.html"
    ],
    "styles": [
      "reset.css",
      "padding=10%_24px",
      "color=darkblue",
      "animation-name=swing"
    ],
    "cssCustomProperties": [
      {
        "element": "body",
        "dataParam": "theme",
        "dataValue": "light",
        "cssVariables": {
          "base-bg-clr": "white"
        }
      },
      {
        "element": "body",
        "dataParam": "theme",
        "dataValue": "dark",
        "cssVariables": {
          "base-bg-clr": "black"
        }
      }
    ]
  }
]

In this example:

Performance By Design: Built for Speed and Efficiency

Grimoire CSS achieves exceptional performance through architectural decisions, algorithmic optimizations, and efficient implementation in Rust. The system is built from the ground up with performance as a core principle:

Grimoire CSS isn’t just fast—it’s blazingly efficient:

Remember that Grimoire CSS is a complete CSS engine that goes far beyond simple class collection and CSS generation. It handles parsing, optimization, vendor prefixing, project management, and provides powerful features like variables, functions, animations, and component composition—all while maintaining this exceptional performance profile.

Benchmark

Grimoire CSS is lightning-fast and highly efficient. While its absolute performance is unquestionable, side-by-side comparisons often offer better perspective. This benchmark is designed to compare Grimoire CSS and Tailwind CSS by accurately measuring build time, memory usage, CPU load, and output file size.

Overview

The benchmark creates a series of standardized test projects, each containing a large number of HTML files with utility classes for both Grimoire CSS and Tailwind CSS. Then each framework is run to process these projects, and various performance metrics are recorded and analyzed.

Measured Metrics

Results

When compared to the latest version of Tailwind CSS (v4.x) processing the same workload of 400,000+ classes across 100,000 files, Grimoire CSS demonstrates significant advantages:

MetricGrimoire CSSTailwind CSSDifference
Build Time2.10s10.58s5.0x faster
Peak Memory Usage111.2 MB344.97 MB3.1x less memory
Average Memory Usage45.76 MB182.31 MB4.0x less memory
CPU User Time755.11ms7.77s10.3x less
CPU System Time1.33s60.89s45.7x less
Class Processing Speed190,684 cls/s37,824 cls/s5.0x faster
Memory Efficiency3,597 cls/MB1,160 cls/MB3.1x more efficient
Output Size5.05 MB5.66 MB1.1x smaller

These performance advantages translate into:

View benchmark README

A Streamlined CLI with a Strict and Straightforward API

Grimoire CSS comes with a minimal but powerful CLI (Command Line Interface) that’s designed for simplicity and efficiency. Whether you’re integrating it into your build process or running it manually, the CLI gets the job done without unnecessary complexity.

The main CLI commands are:

Optional parallel project builds

If your config defines multiple independent projects (multiple output files), Grimoire CSS can build them in parallel.

Example:

GRIMOIRE_CSS_JOBS=4 grimoire_css build

Grimoire CSS’s CLI is built for developers who want power without bloat. It’s direct, no-nonsense, and integrates smoothly into any project or bundler.

Easy Migration with Transmutator

The canonical Transmutator is built into Grimoire CSS. It is available through the Rust API, the main CLI and the MCP server without installing another binary.

The typed Rust entrypoints are transmutator::transmute_css and transmutator::transmute_paths. Both return JSON-compatible data conforming to the external Scrolls convention.

Migration supports selectors beginning with a class, including compound classes, descendants, child selectors and pseudo selectors, plus media queries and nested media queries. Other at-rules (such as @layer, @supports, @keyframes and @import) and selectors without a leading class are rejected with an error; the tool does not silently produce a partial migration. Split unsupported rules out of framework-generated CSS before converting the supported rules.

The leading class must be usable as a plain Scroll name. Rename incompatible classes such as a:b, a__b or 123 before migration. Literal underscores in selector suffixes and values are preserved; duplicate declarations retain their last cascade position within each Scroll.

If different Scrolls may depend on their relative CSS order, migration rejects the complete input and identifies the conflicting selectors and declarations. The check is conservative about shorthand/logical properties and selector/media overlap. Keep order-dependent CSS in an original file connected through shared.styles, and link the shared output stylesheet at the intended position. Ordinary Scroll ordering is unchanged. The check covers the submitted CSS, not its order relative to other stylesheets or existing project Scrolls.

File migration rejects relative asset URLs because Scrolls do not retain the source stylesheet directory. Use absolute or root-relative URLs before migration; local url(#fragment) references remain supported. Inline input has no source base, so its relative URLs are interpreted at the eventual output location. Unicode whitespace and escaped whitespace inside CSS identifiers are preserved.

Literal $ characters and empty custom properties are preserved. CSS text such as mfs(...), mrs(...) and g-invert(...) is not evaluated as Grimoire functions during migration. Animation references retain their names without importing Grimoire keyframes; keep the original keyframe stylesheet connected. Standard property names are normalized to lowercase; custom-property names retain their case. Names that cannot be represented as Spell components, such as --foo\=bar, --foo__bar or --цвет, are rejected before writing.

A CSS property that would invoke a Grimoire abbreviation, g-anim, or a Scroll with the same name is rejected rather than compiled with a different meaning. Rename conflicting Scrolls or keep unsupported CSS in shared.styles. Authored Grimoire variables, functions, abbreviations and breakpoints keep their normal behavior.

For example, .button { color: red; } produces:

{
  "scrolls": [
    {
      "name": "button",
      "spells": ["color=red"]
    }
  ]
}

Try the same canonical Transmutator below in Desk: paste CSS or upload files to download external Scroll JSON. Unsupported CSS produces an explicit error; preserve those styles separately through shared.styles.

Usage and Distribution

Grimoire CSS is built to integrate seamlessly into a wide range of ecosystems. It supports both filesystem-based and in-memory operations, making it perfect for traditional web development and dynamic runtime environments. It’s distributed in three ways to give you maximum flexibility:

Working Modes

Grimoire CSS offers two primary modes of operation:

  1. Filesystem Mode (Traditional):

    • Works with files on disk
    • Reads input files and writes CSS output to specified locations
    • Perfect for build-time CSS generation
    • Uses the standard configuration file approach
  2. In-Memory Mode:

    • Processes CSS entirely in memory
    • No filesystem operations required
    • Ideal for runtime CSS generation or serverless environments
    • Accepts configuration and content directly through API
    • Returns compiled CSS without writing to disk

Example of using In-Memory mode in Rust:

use grimoire_css_lib::{config::{ConfigInMemory, ConfigInMemoryEntry}, start_in_memory};
use std::collections::HashMap;

let config = ConfigInMemory {
    projects: vec![ConfigInMemoryEntry {
        name: "example".to_string(),
        content: vec![r#"<div class="color=red">Hello</div>"#.to_string()],
    }],
    browserslist_content: Some("last 2 versions".to_string()),
    variables: None,
    scrolls: None,
    custom_animations: HashMap::new(),
};

let result = start_in_memory(&config)?;
// result contains Vec<CompiledCssInMemory> with your generated CSS

The core of Grimoire CSS is architected entirely in Rust, ensuring top-notch performance and scalability. The main repository compiles both into a standalone executable (SEA) and a Rust crate, meaning you can use it in different environments with ease.

The grimoire-css-js takes the core crate and wraps it into a Node.js-compatible interface, which is then compiled into an npm package. Whether you’re working with Rust, Node.js, or need a direct CLI, Grimoire CSS is ready to integrate into your workflow and bring powerful CSS management wherever you need it.

Desk

Here is the Desk. Experiment with spells right here in the web UI version of the Grimoire CSS Playground. Or try the web UI Grimoire CSS Transmutator and convert existing CSS to Grimoire CSS format. Upload CSS files or paste code directly. Download JSON configurations that work immediately with your existing class names.

NOTE: Desk uses an in-memory version of the Grimoire CSS engine, so it does not have all features of the full engine yet.

Loading components...

|
Connecting…
HTML + Grimoire CSS
Preview
Error
Cast time: -s
Copied!

Installation

Rust crate:

If you’re using Rust, simply add Grimoire CSS to your Cargo.toml, and follow the link for documentation about crate: docs.rs.

cargo install grimoire_css

or

cargo add grimoire_css

Single Executable Application (SEA):

  1. Download the binary for your operating system from the releases page.
  2. Add the binary to your system’s $PATH (optional for easier usage).

NPM Library:

npm i @persevie/grimoire-css-js

Once installed, you can run the following commands:

Initialize a Grimoire CSS config in your project:

grimoire_css init

or if you are using NPM library:

grimoire-css-js init

Build your CSS using the Grimoire CSS config:

grimoire_css build

or if you are using NPM library:

grimoire-css-js build

MCP Server

The optional grimoire_css_mcp executable exposes 19 project tools and four resources over local stdio, using MCP revision 2025-11-25.

Installation and connection

You need an MCP client that supports local stdio servers and the grimoire_css_mcp executable. The executable includes the CSS engine; it does not require a separate grimoire_css CLI, Node.js, an NPM package, or a hosted service. Ordinary CSS builds can continue without MCP.

Choose one installation method:

cargo build --locked --release --features mcp --bin grimoire_css_mcp

The local build produces target/release/grimoire_css_mcp (.exe on Windows). Alternatively, install this checkout into Cargo’s bin directory with cargo install --path . --locked --features mcp --bin grimoire_css_mcp.

Release asset names are:

PlatformAsset
Linux x64grimoire_css_mcp-linux-x64
macOS Intelgrimoire_css_mcp-darwin-x64
macOS Apple Silicongrimoire_css_mcp-darwin-arm64
Windows x64grimoire_css_mcp-win32-x64.exe

Configure your client to launch the executable with an absolute project root. Clients that accept an mcpServers JSON configuration can use the following; other clients expose equivalent command and argument fields in their settings:

{
  "mcpServers": {
    "grimoire-css": {
      "command": "/absolute/path/to/grimoire_css_mcp",
      "args": ["--root", "/absolute/path/to/project"]
    }
  }
}

On Windows, include .exe and escape backslashes in JSON, for example "command": "C:\\Tools\\grimoire_css_mcp.exe". The root must be the project directory, not the executable’s directory or the grimoire/config subdirectory. Restart or reload the MCP connection after changing its configuration. The client starts the process automatically; no separate terminal process, network port, or Grimoire API key is needed.

The command uses newline-delimited JSON-RPC over stdio. It writes only MCP messages to stdout. The tool schemas contain no root override, so the agent cannot switch projects after launch.

Relative configuration paths are resolved against the selected project root, independently of the launcher’s working directory. This includes project input globs, shared CSS output and source files, and critical CSS source and target files. Absolute paths retain their usual meaning. The same path resolution is used by the CLI and public Rust APIs; the server does not change process cwd.

For a new project, the agent can read grimoire://documentation and grimoire://config-schema, call grimoire_init, edit the generated standard configuration with its normal workspace tools, validate it through the MCP analysis tools, and call the existing grimoire_build operation.

If configuration loading rejects cyclic Scroll inheritance, grimoire_init, grimoire_build, and grimoire_shorten return a tool error and preserve the configuration file byte for byte, matching the CLI and public Rust commands. The server remains available for subsequent requests.

First session

  1. Ask the agent to read the component catalog and project configuration with grimoire_config_summary. On a new project, ask it to initialize Grimoire CSS with grimoire_init, then edit the generated configuration for your inputs and outputs using its workspace tools.
  2. Ask it to explain a proposed Spell with grimoire_explain, or validate a list with grimoire_validate_spells. For example, the latter accepts {"tokens":["display=flex","padding=16px"]}.
  3. After config changes, run grimoire_validate_config. When you want to verify and build the project, run grimoire_check_project; it writes build outputs.
  4. For migration, preview with grimoire_transmute_css, then explicitly request grimoire_import_css to install the generated Scrolls. The source classes must be present in configured input files to produce CSS in the build.

An import request for a supported rule can use:

{
  "content": ".button { color: red; }",
  "import_name": "buttons"
}

This creates grimoire/config/grimoire.buttons.scrolls.json after validation, then checks and builds the project. Existing imports require explicit "replace": true. Inspect structuredContent.data.valid, not only the absence of a protocol error. Domain errors use isError: true with structuredContent.error; a completed validation can return valid: false.

You can ask in natural language: “Use Grimoire CSS MCP to inspect my config, validate the proposed Spells, and build the project.” The agent makes the tool calls; you do not need to send JSON-RPC messages manually.

Troubleshooting

Validation and output

The initialize instructions and grimoire://primer require agents to:

  1. validate every proposed spell with grimoire_validate_spells;
  2. validate every created or modified config with grimoire_validate_config;
  3. run grimoire_check_project after project changes;
  4. avoid claiming completion unless the relevant report has valid: true.

grimoire_check_project performs schema and engine config validation, checks all indexed project spells, requires a clean lint result, and invokes the real filesystem build. It can therefore write the configured build outputs.

The resulting guarantees are deliberately precise:

These checks verify engine acceptance and build success; they do not establish visual equivalence to the original stylesheet or a design.

Resources

ResourceContent
grimoire://primerGrimoire syntax and tool usage guide for agents
grimoire://componentsCSS component names and abbreviations
grimoire://config-schemaProject configuration JSON Schema
grimoire://documentationThe project documentation bundled with the executable

Tools

ToolOperationArguments
grimoire_explainExpand a Spell or Scroll and compile its CSStoken
grimoire_config_summaryRead project configurationnone
grimoire_indexIndex project Spells and Scrollsoptional positive top
grimoire_lintReport project errors and warningsnone
grimoire_dryFind repeated Spell groupsoptional positive min_support and min_items
grimoire_list_variablesList Grimoire variablesnone
grimoire_list_scrollsList Scroll namesnone
grimoire_refsFind references of a specified kindkind, query
grimoire_stats_spellsCount Spell usageoptional positive top
grimoire_refs_autoFind references by variable, Scroll or Spell namequery
grimoire_statsReport usage statisticsoptional group, token, top
grimoire_validate_configValidate schemas and load the configurationnone
grimoire_validate_spellsParse and compile proposed tokenstokens
grimoire_check_projectValidate, lint and build the projectnone
grimoire_transmute_cssPreview CSS conversion and validate generated Spellscontent, optional with_oneliner
grimoire_import_cssImport CSS as Scrolls, then check and build the projectexactly one of content/paths, import_name, optional replace/with_oneliner
grimoire_initInitialize project configurationnone
grimoire_buildBuild configured CSS outputsoptional force_version_update
grimoire_shortenRewrite source files with shortened Spellsnone

grimoire_init, grimoire_build, grimoire_shorten, grimoire_check_project and grimoire_import_css can write files. Other tools provide read-only analysis. Import rollback covers the imported Scroll file; generated build outputs are not transactional. See CSS migration for supported input, cascade checks and the shared.styles fallback.

The Arcane Circle

Grimoire CSS gives you the freedom to create styles that work exactly the way you want them to - no rigid rules or constraints. Whether you’re crafting dynamic interactions or fine-tuning layouts, Grimoire adapts to your needs, making each step straightforward and rewarding.

So, come join us. Share your work, exchange your thoughts, and help us keep pushing CSS to be more flexible and enjoyable.

The Arcane Circle, or simply the Circle, is a place where you can share your configs, scrolls, variables, components, or UI kits. It’s where you can catch the latest news, follow development, influence the project, and interact with other members of the Circle.

The Circle is currently under development.

The First Member

Hello! My name is Dmitrii Shatokhin, and I am the creator of Grimoire CSS. I invented the Spell concept and all the other ideas behind the project. Grimoire CSS is the result of countless hours of work and dedication, and I am proud to have made it open source.

But this is just the beginning. I am committed to the ongoing development of Grimoire CSS and its entire ecosystem - there are many plans and tasks ahead, which I strive to manage transparently on GitHub. My vision is to grow the Arcane Circle community and bring all these ideas to life.

I would be truly grateful for any support you can offer - whether it’s starring the project on GitHub, leaving feedback, recommending it to others, contributing to its development, helping to promote Grimoire CSS, or even sponsoring the project or my work.

Thank you!

Craft Your Code, Cast Your Spells