> For the complete documentation index, see [llms.txt](https://bryan-guner.gitbook.io/my-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bryan-guner.gitbook.io/my-docs/redux/repos/examples/real-world/node_modules/postcss-custom-selectors.md).

# PostCSS Custom Selectors

[![NPM Version](https://img.shields.io/npm/v/postcss-custom-selectors.svg)](https://www.npmjs.com/package/postcss-custom-selectors) [![CSS Standard Status](https://cssdb.org/badge/custom-selectors.svg)](https://cssdb.org/#custom-selectors) [![Build Status](https://img.shields.io/travis/postcss/postcss-custom-selectors.svg)](https://travis-ci.org/postcss/postcss-custom-selectors) [![Support Chat](https://img.shields.io/badge/support-chat-blue.svg)](https://gitter.im/postcss/postcss)

[PostCSS Custom Selectors](https://github.com/postcss/postcss-custom-selectors) lets you use Custom Selectors in CSS, following the [CSS Extensions](https://drafts.csswg.org/css-extensions/#custom-selectors) 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 Selectors](https://github.com/postcss/postcss-custom-selectors) to your project:

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

Use [PostCSS Custom Selectors](https://github.com/postcss/postcss-custom-selectors) to process your CSS:

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

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

Or use it as a [PostCSS](https://github.com/postcss/postcss) plugin:

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

postcss([
  postcssCustomSelectors(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```

[PostCSS Custom Selectors](https://github.com/postcss/postcss-custom-selectors) runs in all Node environments, with special instructions for:

| [Node](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-custom-selectors/INSTALL.md#node) | [PostCSS CLI](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-custom-selectors/INSTALL.md#postcss-cli) | [Webpack](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-custom-selectors/INSTALL.md#webpack) | [Create React App](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-custom-selectors/INSTALL.md#create-react-app) | [Gulp](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-custom-selectors/INSTALL.md#gulp) | [Grunt](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-custom-selectors/INSTALL.md#grunt) |
| -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |

## Options

### preserve

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

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

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

/* becomes */

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

article :--heading + p {}
```

### 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.

```js
postcssCustomSelectors({
  importFrom: 'path/to/file.css' // => @custom-selector :--heading h1, h2, h3;
});
```

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

/* becomes */

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

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.

```js
postcssCustomSelectors({
  importFrom: [
    'path/to/file.css',
    'and/then/this.js',
    'and/then/that.json',
    {
      customSelectors: { ':--heading': 'h1, h2, h3' }
    },
    () => {
      const customProperties = { ':--heading': 'h1, h2, h3' };

      return { customProperties };
    }
  ]
});
```

### 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.

```js
postcssCustomSelectors({
  exportTo: 'path/to/file.css' // @custom-selector :--heading h1, h2, h3;
});
```

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.

```js
const cachedObject = { customSelectors: {} };

postcssCustomSelectors({
  exportTo: [
    'path/to/file.css',   // @custom-selector :--heading h1, h2, h3;
    'and/then/this.js',   // module.exports = { customSelectors: { ':--heading': 'h1, h2, h3' } }
    'and/then/this.mjs',  // export const customSelectors = { ':--heading': 'h1, h2, h3' } }
    'and/then/that.json', // { "custom-selectors": { ":--heading": "h1, h2, h3" } }
    cachedObject,
    customProperties => {
      customProperties    // { ':--heading': 'h1, h2, h3' }
    }
  ]
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bryan-guner.gitbook.io/my-docs/redux/repos/examples/real-world/node_modules/postcss-custom-selectors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
