PrettyCSS

raw JSON →
0.3.19 verified Fri May 01 auth: no javascript maintenance

PrettyCSS is a CSS3-compliant parser, lint checker, and pretty printer for Node.js and browsers. It validates CSS property names and values, beautifies code to standard formats, and can minify styles. Version 0.3.19 (last release) has seen no updates since 2014; the project is in maintenance mode with no active development. It offers unique CSS3 support and thorough value validation compared to alternatives like CSSO or clean-css, but lacks modern features like PostCSS compatibility.

error TypeError: PrettyCSS is not a constructor
cause Using CommonJS require() with ESM package.
fix
Use import PrettyCSS from 'prettycss'; or const PrettyCSS = require('prettycss').default;
error SyntaxError: Unexpected token @
cause CSS contains modern syntax like @supports not supported by PrettyCSS.
fix
Pre-process CSS with a tool like PostCSS to strip unsupported rules, or avoid using modern syntax.
error Cannot find module 'prettycss'
cause Package not installed or being used in an environment without proper module resolution.
fix
Run npm install prettycss and ensure the project uses CommonJS or ESM correctly.
gotcha The package is unmaintained since 2014; no CSS4 or modern syntax support.
fix Consider using a maintained alternative like PostCSS or stylelint.
gotcha The beautify function may produce invalid output for complex CSS (e.g., @supports, @container).
fix Always verify output against a browser CSS parser.
gotcha Lint rules are hardcoded and cannot be extended; no configuration file.
fix Use stylelint for customizable linting.
npm install PrettyCSS
yarn add PrettyCSS
pnpm add PrettyCSS

Parses a CSS file, lints it, and beautifies it with 2-space indentation.

import { parse, beautify, lint } from 'prettycss';
import fs from 'fs';
const css = fs.readFileSync('style.css', 'utf8');
const ast = parse(css, { source: 'style.css' });
const errors = lint(ast, { source: 'style.css' });
if (errors.length) {
  console.log('Lint errors:', errors);
}
const prettyCss = beautify(ast, { indent: '  ' });
fs.writeFileSync('pretty.css', prettyCss);
console.log('Beautified CSS saved to pretty.css');