Windi CSS

3.5.6 · deprecated · verified Sun Apr 19

Windi CSS was an on-demand, utility-first CSS framework designed as a performant alternative to Tailwind CSS, aiming to address compilation speed issues in larger projects by providing quicker hot module replacement (HMR) and eliminating the need for production purging. It dynamically scanned HTML and CSS to generate utilities. The project officially announced its deprecation in March 2022, recommending users migrate to Tailwind CSS v3 or newer. While its last stable version, 3.5.6, included some Tailwind v3 utility classes and bug fixes, no further active development, new features, or security updates are expected. Key differentiators during its active period included its 'on-demand' compilation approach and extensive framework integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically use Windi CSS to process HTML content, extract utility classes, and generate the corresponding CSS, including preflight styles, within a Node.js environment.

import { Processor, HTMLParser } from 'windicss';
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';

async function generateWindiCSS() {
  const htmlContent = `
    <div class="p-4 bg-blue-500 text-white rounded shadow-lg">
      <h1 class="text-2xl font-bold mb-2">Hello Windi CSS!</h1>
      <p class="text-sm">This is a paragraph with some utility classes.</p>
      <button class="px-3 py-2 bg-green-500 hover:bg-green-600 rounded">Click Me</button>
    </div>
  `;

  // Initialize the Windi CSS processor
  const processor = new Processor();

  // Parse HTML to extract utility classes
  const htmlParser = new HTMLParser(htmlContent);
  const { classes } = htmlParser.parseClasses();

  // Interpret the extracted classes to generate Windi CSS utilities
  const interpreted = processor.interpret(classes.join(' '));

  // Generate the actual CSS
  const { css } = await interpreted.generate();

  // Optionally, include preflight base styles
  const preflightSheet = processor.preflight();
  const preflightCSS = preflightSheet.build();

  const finalCSS = `${preflightCSS}\n${css}`;

  const outputPath = resolve('./dist/windicss-output.css');
  writeFileSync(outputPath, finalCSS);

  console.log(`Windi CSS generated and written to ${outputPath}`);
}

generateWindiCSS().catch(console.error);

view raw JSON →