Skip to content

BaroCSSCSS Runtime Engine

A CSS parsing and generation engine that brings Tailwind's utility-first approach to runtime environments

What is BaroCSS?

BaroCSS is a CSS parsing and generation engine that brings Tailwind's utility-first approach to runtime environments. Built from the ground up to support Tailwind CSS syntax, it enables dynamic CSS generation without build processes. Inspired by Tailwind CSS and UnoCSS.

Core Architecture

BaroCSS consists of three main packages:

  • @barocss/kit - Core parsing and generation engine
  • @barocss/browser - Browser runtime with DOM change detection
  • @barocss/server - Server runtime for static CSS generation

Runtime-First Approach

Traditional Build Process:

bash
# Write classes → Build → Wait → Deploy
<div class="bg-blue-500 hover:bg-blue-700">Button</div>
# Requires build step and deployment

BaroCSS Runtime:

bash
# Write classes → Generate CSS instantly
<div class="bg-blue-500 hover:bg-blue-700">Button</div>
# CSS generated at runtime, no build needed

Key Capabilities

Core Engine (@barocss/kit):

typescript
import { parseClassToAst, generateCss, createContext } from '@barocss/kit';

const context = createContext();
const ast = parseClassToAst('bg-blue-500 text-white p-4', context);
const css = generateCss('bg-blue-500 text-white p-4', context);

Browser Runtime (@barocss/browser):

typescript
import { BrowserRuntime } from '@barocss/browser';

const runtime = new BrowserRuntime();
runtime.observe(document.body, { scan: true });
// Automatically detects and styles new classes

Server Runtime (@barocss/server):

typescript
import { ServerRuntime } from '@barocss/server';

const runtime = new ServerRuntime();
const css = runtime.generateCss('bg-blue-500 text-white p-4');
// Generate CSS for server-side rendering

Perfect for Dynamic Content

BaroCSS excels when you need to generate CSS for dynamic content:

typescript
// User-generated content with arbitrary values
const userContent = `
<div class="w-[${width}px] h-[${height}px] bg-[${color}] rounded-[${radius}px]">
  Dynamic content styled instantly
</div>
`;

// BaroCSS parses arbitrary values like w-[400px], bg-[#ff0000] at runtime
Hello BaroCSS!

Released under the MIT License.