A CSS selector compiler and engine that turns CSS selectors into functions to test or find matching elements in a DOM tree. Current stable version is 7.0.0, released as an ESM-only package requiring Node.js >=20.19.0. The engine uses a right-to-left execution model for optimal performance (O(n) vs O(n^(k+1)) for left-to-right engines). It fully implements CSS3 selectors and most CSS4 selectors, with partial jQuery/Sizzle extension support. Ships TypeScript types. Breaking changes in v7 include removal of CommonJS support, removal of deprecated exports (_compileToken, aliases, filters, pseudos), and no more deep imports. Prior major versions include v6 (dual CJS/ESM, pseudos option, `:where` support) and v5 (adapter API changes). Release cadence is periodic; maintained by fb55.
npm install css-selectNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of cssSelect and compile functions with htmlparser2 DOM, including selector compilation and options.
Use import syntax or migrate to Node.js >=20.19.0 if you must use require() via dynamic import.
Use root package imports only. For types, import from 'css-select' directly.
Use the `pseudos` option in cssSelect() instead of extending these objects.
Use _compileUnsafe instead.
Set `relativeSelector: false` option to disable context-scoping.
Provide an `adapter` option implementing the required methods (isTag, getChildren, etc.).
Replace _compileToken with _compileUnsafe.
Ensure you are passing a valid DOM tree from htmlparser2 or provide a proper adapter. Use compile() if you need to test single elements.
Remove unsupported syntax; css-select does not support regex selectors.