You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

postcss-color-hex-alpha

Package Overview
Dependencies
Maintainers
5
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-color-hex-alpha

Use 4 & 8 character hex color notation in CSS


Version published
Weekly downloads
5.7M
decreased by-1.43%
Maintainers
5
Created
Weekly downloads
 

Package description

What is postcss-color-hex-alpha?

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.

What are postcss-color-hex-alpha's main functionalities?

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); }'
});

Other packages similar to postcss-color-hex-alpha

Readme

Source

PostCSS Color Hex Alpha PostCSS Logo

npm version Build Status Discord

Baseline Status CSS Standard Status

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);
}

Usage

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 */);

PostCSS Color Hex Alpha runs in all Node environments, with special instructions for:

Options

preserve

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;
}

Keywords

FAQs

Package last updated on 19 Feb 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc