Skip to content

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

License

Notifications You must be signed in to change notification settings

postcss/postcss-relative-opacity

Repository files navigation

PostCSS Relative Opacity

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

Upcoming CSS Colors 5 allows you to change any color including adding opacity. Firefox still doesn’t support this syntax and plugin partially polyfills this 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 at 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')
  ]
}

About

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

Resources

License

Stars

Watchers

Forks