githubEdit

PostCSS Environment Variables

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

PostCSS Environment Variablesarrow-up-right lets you use env() variables in CSS, following the CSS Environment Variablesarrow-up-right specification.

@media (max-width: env(--branding-small)) {
  body {
    padding: env(--branding-padding);
  }
}

/* becomes */

@media (min-width: 600px) {
  body {
    padding: 20px;
  }
}

/* when the `importFrom` option is: {
  "environmentVariables": {
    "--branding-small": "600px",
    "--branding-padding": "20px"
  }
} */

Usage

Add PostCSS Environment Variablesarrow-up-right to your project:

Use PostCSS Environment Variablesarrow-up-right to process your CSS:

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

PostCSS Environment Variablesarrow-up-right runs in all Node environments, with special instructions for:

Options

importFrom

The importFrom option specifies sources where Environment Variables can be imported from, which might be 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 environmentVariables or variables-variables key.

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

Last updated

Was this helpful?