Building MasalaCSS: a CSS runtime with no build step
What I learned parsing class names in the browser and keeping it fast.
by Dhruv Sood
MasalaCSS started with a simple question: what if utility classes didn't need a compiler at all?
The idea
Most utility-first CSS tools scan your source files at build time and emit a stylesheet. MasalaCSS does the same job in the browser: it reads class names as they appear in the DOM and generates the matching rules on the fly.
<script src="https://unpkg.com/masalacss"></script>
<div class="p-4 rounded-lg bg-violet-500">Hello</div>
No build step, no config file.
Keeping it fast
- Parse each class name once and cache the result.
- Batch new rules and insert them in a single pass.
- Only generate CSS for classes that are actually in the page.
What I learned
Designing the API was harder than writing the parser. A runtime is only as good as the names people can guess without reading docs.