Stylis compiles nested, prefixed, and minified CSS from concise input in JavaScript. It exposes tokenize, compile, and middleware hooks and ships as an npm package with ESM and tree-shaking support.
Overview
Stylis is a small CSS preprocessor implemented as a library you import into JavaScript projects. It parses author-friendly syntax—such as nested rules with `&` selectors—and emits expanded CSS, applying vendor prefixing and optional minification along the way.
The API centers on compiling strings into an abstract syntax structure you can traverse or stringify. Middleware helpers let you plug into the compile pipeline; the bundled middleware file shows how to implement custom passes, including vendor prefix handling and custom serializers.
CSS custom properties are supported, including exotic values described in the spec, with guidance to quote or parenthesize ambiguous `{` and `}` in variables to avoid clashes with implicit block termination. The project publishes to npm and documents CDN and direct download usage for browser or bundler setups.
Key features
- Nested selector compilation
- Selector namespacing support
- Automatic vendor prefixing
- Optional minification pass
- Middleware compile pipeline
- ESM and tree-shaking friendly
- Tokenize and serialize utilities
- CSS custom properties handling
Use cases
- CSS-in-JS style compilation
- Build-time style preprocessing
- Custom CSS transform pipelines
- Library-internal style processing