Skip to content

๐ŸŒ— PostCSS plugin to transform percentage-based opacity values to more compatible floating-point values.

License

Notifications You must be signed in to change notification settings

mrcgrtz/postcss-opacity-percentage

Folders and files

NameName
Last commit message
Last commit date
Apr 14, 2025
Feb 1, 2024
Sep 3, 2024
Nov 8, 2021
Nov 8, 2021
Nov 8, 2021
Nov 18, 2021
Nov 8, 2021
Oct 18, 2022
Feb 14, 2022
Apr 2, 2025
Sep 3, 2024

Repository files navigation

PostCSS Opacity Percentage

Test Coverage Status Install size XO code style MIT license

PostCSS plugin to transform percentage-based opacity values to more compatible floating-point values.

Install

Using npm:

npm install --save-dev postcss postcss-opacity-percentage

Using yarn:

yarn add --dev postcss postcss-opacity-percentage

Example

/* Input */
.foo {
  opacity: 45%;
}
/* Output */
.foo {
  opacity: 0.45;
}

Usage

postcss([
  require('postcss-opacity-percentage'),
]);

See PostCSS documentation for examples for your environment.

postcss-preset-env

If you are using postcss-preset-env@>=7.3.0, you already have this plugin installed via this package.

Options

preserve

The preserve option determines whether the original percentage value is preserved. By default, it is not preserved.

// Keep the original notation
postcss([
  require('postcss-opacity-percentage')({preserve: true}),
]);
/* Input */
.foo {
  opacity: 45%;
}
/* Output */
.foo {
  opacity: 0.45;
  opacity: 45%;
}

License

MIT ยฉ Marc Gรถrtz