/postcss-relative-opacity

PostCSS plugin to add opacity to any colors with Relative Color Syntax

Primary LanguageJavaScriptMIT LicenseMIT

PostCSS Relative Opacity

PostCSS plugin to add opacity to any colors with Relative Color Syntax.

Upcoming CSS Colors 5 allows to change any color including adding opacity. But Firefox still doesn’t support this syntax. This tool partially polyfill thi syntax via color-mix().

.notice {
  background: oklch(from var(--accent-color) l c h / 30%);
}

will be processed to:

.notice {
  background: color-mix(in srgb, var(--accent-color) 30%, transparent);
}

This polyfill is based on Adam Argyle idea.


  Made in Evil Martians, product consulting for developer tools.


Usage

Step 1: Install plugin:

npm install --save-dev postcss postcss-relative-opacity

Step 2: Check your project for existing PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-relative-opacity'),
    require('autoprefixer')
  ]
}