
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
postcss-color-hex-alpha
Advanced tools
The postcss-color-hex-alpha package is a PostCSS plugin that allows you to use 4- and 8-digit hex color notation in your CSS. This notation includes an alpha channel, which specifies the opacity of the color. The plugin converts these hex colors into their equivalent rgba() or hsla() functions, making it easier to work with colors that include transparency.
Convert 4-digit hex colors to rgba()
This feature allows you to use 4-digit hex colors (e.g., #0f08) in your CSS. The plugin converts these colors into their rgba() equivalents, making it easier to work with colors that include transparency.
const postcss = require('postcss');
const colorHexAlpha = require('postcss-color-hex-alpha');
const css = 'a { color: #0f08; }';
postcss([colorHexAlpha]).process(css).then(result => {
console.log(result.css);
// Output: 'a { color: rgba(0, 255, 0, 0.53); }'
});
Convert 8-digit hex colors to rgba()
This feature allows you to use 8-digit hex colors (e.g., #0000ff80) in your CSS. The plugin converts these colors into their rgba() equivalents, making it easier to work with colors that include transparency.
const postcss = require('postcss');
const colorHexAlpha = require('postcss-color-hex-alpha');
const css = 'a { color: #0000ff80; }';
postcss([colorHexAlpha]).process(css).then(result => {
console.log(result.css);
// Output: 'a { color: rgba(0, 0, 255, 0.5); }'
});
The postcss-color-function package allows you to use color-modifying functions in your CSS, such as color(), which can adjust the lightness, saturation, and alpha of a color. Unlike postcss-color-hex-alpha, which focuses on converting hex colors with alpha channels, postcss-color-function provides a broader range of color manipulation capabilities.
The postcss-color-rgba-fallback package generates hexadecimal color fallbacks for rgba() colors in your CSS. This is useful for ensuring compatibility with older browsers that do not support rgba(). While postcss-color-hex-alpha converts hex colors with alpha channels to rgba(), postcss-color-rgba-fallback works in the opposite direction by providing hex fallbacks for rgba() colors.
npm install postcss-color-hex-alpha --save-dev
PostCSS Color Hex Alpha lets you use 4 & 8 character hex color notation in CSS, following the CSS Color Module specification.
body {
background: #9d9c;
}
/* becomes */
body {
background: rgba(153,221,153,0.8);
}
Add PostCSS Color Hex Alpha to your project:
npm install postcss postcss-color-hex-alpha --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssColorHexAlpha = require('postcss-color-hex-alpha');
postcss([
postcssColorHexAlpha(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
The preserve
option determines whether the original notation
is preserved. By default, it is not preserved.
postcssColorHexAlpha({ preserve: true })
body {
background: #9d9c;
}
/* becomes */
body {
background: rgba(153,221,153,0.8);
background: #9d9c;
}
FAQs
Use 4 & 8 character hex color notation in CSS
The npm package postcss-color-hex-alpha receives a total of 5,103,600 weekly downloads. As such, postcss-color-hex-alpha popularity was classified as popular.
We found that postcss-color-hex-alpha demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.