@acemir/cssom

A pure-JavaScript CSS parser and CSS Object Model implementation.

Library
npm
v0.9.31
25stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity8
Maintenance48
Community28
Maturity40
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture78
Code Quality76
Innovation65
Learning Curve80

@acemir/cssom is a maintained fork of CSSOM.js, a CSS parser written in pure JavaScript that also provides a partial implementation of the CSS Object Model (CSSOM). It parses raw CSS text into a tree of structured rule objects — style rules, at-rules, keyframes, media/container conditions, and their declarations — that can be inspected, mutated, and serialized back to CSS.

Because it has no runtime dependencies and models CSSOM types directly (CSSStyleSheet, CSSStyleRule, CSSStyleDeclaration, and many at-rule types), it is widely used as a headless CSS engine in tools and test environments where a real browser CSSOM isn’t available. It powers CSS handling in DOM emulation stacks and sees millions of weekly downloads.

What You Get

  • CSSOM.parse() that converts CSS text into a navigable tree of rule objects
  • Implementations of core CSSOM types — CSSStyleSheet, CSSStyleRule, CSSStyleDeclaration, and many at-rule classes
  • Round-trip serialization back to CSS via each object’s cssText
  • A dependency-free module usable in Node.js and, via a build step, directly in the browser

Common Use Cases

  • Providing CSSOM support inside headless DOM environments and test runners
  • Parsing and programmatically transforming stylesheets in build tools
  • Inspecting or rewriting CSS rules and declarations without a browser

Under The Hood

Architecture — Each CSSOM interface is a small constructor in lib/ (CSSStyleSheet, CSSStyleRule, CSSGroupingRule, CSSMediaRule, CSSKeyframesRule, CSSStyleDeclaration, and more), and lib/parse.js tokenizes CSS text and assembles these objects into a rule tree. A clone.js helper and per-type cssText getters handle deep copying and serialization back to CSS.

Tech Stack — Pure JavaScript with zero runtime dependencies. A build.js script bundles the module into a single browser-global file, while CommonJS consumers import it directly under Node.js.

Code Quality — The spec/ directory holds Jasmine-style specs for individual rule types (CSSStyleRule, CSSGroupingRule, CSSImportRule, CSSStyleDeclaration, and others), giving per-interface test coverage of parsing and serialization behavior.

API Design — The API mirrors the browser CSSOM closely, so developers already familiar with document.styleSheets semantics can use cssRules, selectorText, style, and cssText with no new mental model. Parsing is a single function call returning plain, inspectable objects.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search