https://github.com/mrcgrtz/postcss-opacity-percentage
๐ PostCSS plugin to transform percentage-based opacity values to more compatible floating-point values.
https://github.com/mrcgrtz/postcss-opacity-percentage
css css4 opacity postcss postcss-plugin
Last synced: 3 months ago
JSON representation
๐ PostCSS plugin to transform percentage-based opacity values to more compatible floating-point values.
- Host: GitHub
- URL: https://github.com/mrcgrtz/postcss-opacity-percentage
- Owner: mrcgrtz
- License: mit
- Created: 2021-11-08T14:38:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-17T17:52:59.000Z (4 months ago)
- Last Synced: 2025-03-29T10:48:01.794Z (4 months ago)
- Topics: css, css4, opacity, postcss, postcss-plugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/postcss-opacity-percentage
- Size: 807 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# PostCSS Opacity Percentage
[](https://github.com/mrcgrtz/postcss-opacity-percentage/actions/workflows/test.yml)
[](https://coveralls.io/github/mrcgrtz/postcss-opacity-percentage?branch=main)
[](https://packagephobia.now.sh/result?p=postcss-opacity-percentage)
[](https://github.com/sindresorhus/xo)
[](https://github.com/mrcgrtz/postcss-opacity-percentage/blob/main/LICENSE.md)[PostCSS](https://github.com/postcss/postcss) plugin to transform [percentage-based opacity values](https://www.w3.org/TR/css-color-4/#transparency) to more compatible floating-point values.
## Install
Using [npm](https://www.npmjs.com/get-npm):
```bash
npm install --save-dev postcss postcss-opacity-percentage
```Using [yarn](https://yarnpkg.com/):
```bash
yarn add --dev postcss postcss-opacity-percentage
```## Example
```css
/* Input */
.foo {
opacity: 45%;
}
``````css
/* Output */
.foo {
opacity: 0.45;
}
```## Usage
```js
postcss([
require('postcss-opacity-percentage'),
]);
```See [PostCSS](https://github.com/postcss/postcss) documentation for examples for your environment.
### `postcss-preset-env`
If you are using [`postcss-preset-env@>=7.3.0`](https://github.com/csstools/postcss-plugins/blob/main/plugin-packs/postcss-preset-env/CHANGELOG.md#730-january-31-2022), 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.
```js
// Keep the original notation
postcss([
require('postcss-opacity-percentage')({preserve: true}),
]);
``````css
/* Input */
.foo {
opacity: 45%;
}
``````css
/* Output */
.foo {
opacity: 0.45;
opacity: 45%;
}
```## License
MIT ยฉ [Marc Gรถrtz](https://marcgoertz.de/)