githubEdit

PostCSS Custom Properties

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

PostCSS Custom Propertiesarrow-up-right lets you use Custom Properties in CSS, following the CSS Custom Propertiesarrow-up-right specification.

:root {
  --color: red;
}

h1 {
  color: var(--color);
}

/* becomes */

:root {
  --color: red;
}

h1 {
  color: red;
  color: var(--color);
}

Usage

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

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

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

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

Options

preserve

The preserve option determines whether Custom Properties and properties using custom properties should be preserved in their original form. By default, both of these are preserved.

importFrom

The importFrom option specifies sources where Custom Properties 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 Properties using the customProperties or custom-properties key.

See example imports written in CSSarrow-up-right, JSarrow-up-right, and JSONarrow-up-right.

exportTo

The exportTo option specifies destinations where Custom Properties 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 Properties using the customProperties or custom-properties key.

See example exports written to CSSarrow-up-right, JSarrow-up-right, MJSarrow-up-right, and JSONarrow-up-right.

Last updated

Was this helpful?