githubEdit

PostCSS Custom Selectors

NPM Versionarrow-up-right CSS Standard Statusarrow-up-right Build Statusarrow-up-right Support Chatarrow-up-right

PostCSS Custom Selectorsarrow-up-right lets you use Custom Selectors in CSS, following the CSS Extensionsarrow-up-right specification.

@custom-selector :--heading h1, h2, h3;

article :--heading + p {
  margin-top: 0;
}

/* becomes */

article h1 + p, article h2 + p, article h3 + p {}

Usage

Add PostCSS Custom Selectorsarrow-up-right to your project:

npm install postcss-custom-selectors --save-dev

Use PostCSS Custom Selectorsarrow-up-right to process your CSS:

const postcssCustomSelectors = require('postcss-custom-selectors');

postcssCustomSelectors.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSSarrow-up-right plugin:

PostCSS Custom Selectorsarrow-up-right runs in all Node environments, with special instructions for:

Options

preserve

The preserve option determines whether custom selectors and rules using custom selectors should be preserved in their original form.

importFrom

The importFrom option specifies sources where custom selectors can be imported from, which might be CSS, JS, and JSON files, functions, and directly passed objects.

Multiple sources can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, functions, and objects will need to namespace custom selectors using the customProperties or custom-properties key.

exportTo

The exportTo option specifies destinations where custom selectors can be exported to, which might be CSS, JS, and JSON files, functions, and directly passed objects.

Multiple destinations can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, and objects will need to namespace custom selectors using the customProperties or custom-properties key.

Last updated

Was this helpful?