postcss-color-functional-notation

Use space and slash separated color notation in CSS

MIT-0 55 个版本
安装
npm install postcss-color-functional-notation
yarn add postcss-color-functional-notation
pnpm add postcss-color-functional-notation
bun add postcss-color-functional-notation
README

PostCSS Color Functional Notation PostCSS Logo

npm install postcss-color-functional-notation --save-dev

PostCSS Color Functional Notation lets you use space and slash separated color notation in CSS, following the CSS Color specification.

:root {
	--firebrick: rgb(178 34 34);
	--firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
	--firebrick-hsl: hsla(0 68% 42%);
	--firebrick-hsl-a50: hsl(0 68% 42% / 50%);
}

/* becomes */

:root {
	--firebrick: rgb(178, 34, 34);
	--firebrick-a50: rgba(179, 34, 34, 0.5);
	--firebrick-hsl: hsl(0, 68%, 42%);
	--firebrick-hsl-a50: hsla(0, 68%, 42%, 0.5);
}

Usage

Add PostCSS Color Functional Notation to your project:

npm install postcss postcss-color-functional-notation --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssColorFunctionalNotation = require('postcss-color-functional-notation');

postcss([
	postcssColorFunctionalNotation(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

Options

preserve

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

postcssColorFunctionalNotation({ preserve: true })
:root {
	--firebrick: rgb(178 34 34);
	--firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
	--firebrick-hsl: hsla(0 68% 42%);
	--firebrick-hsl-a50: hsl(0 68% 42% / 50%);
}

/* becomes */

:root {
	--firebrick: rgb(178, 34, 34);
	--firebrick-a50: rgba(179, 34, 34, 0.5);
	--firebrick-hsl: hsl(0, 68%, 42%);
	--firebrick-hsl: hsla(0 68% 42%);
	--firebrick-hsl-a50: hsla(0, 68%, 42%, 0.5);
}

@supports (color: rgb(0 0 0 / 0)) {
:root {
	--firebrick: rgb(178 34 34);
	--firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
}
}

@supports (color: hsl(0 0% 0% / 0)) {
:root {
	--firebrick-hsl-a50: hsl(0 68% 42% / 50%);
}
}

enableProgressiveCustomProperties

The enableProgressiveCustomProperties option determines whether the original notation is wrapped with @supports when used in Custom Properties. By default, it is enabled.

[!NOTE] We only recommend disabling this when you set preserve to false or if you bring your own fix for Custom Properties.
See what the plugin does in its README.

postcssColorFunctionalNotation({ enableProgressiveCustomProperties: false })
:root {
	--firebrick: rgb(178 34 34);
	--firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
	--firebrick-hsl: hsla(0 68% 42%);
	--firebrick-hsl-a50: hsl(0 68% 42% / 50%);
}

/* becomes */

:root {
	--firebrick: rgb(178, 34, 34);
	--firebrick: rgb(178 34 34);
	--firebrick-a50: rgba(179, 34, 34, 0.5);
	--firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
	--firebrick-hsl: hsl(0, 68%, 42%);
	--firebrick-hsl: hsla(0 68% 42%);
	--firebrick-hsl-a50: hsla(0, 68%, 42%, 0.5);
	--firebrick-hsl-a50: hsl(0 68% 42% / 50%);
}

Custom properties do not fallback to the previous declaration

版本列表
8.0.5 2026-06-14
8.0.4 2026-05-13
8.0.3 2026-04-12
8.0.2 2026-02-21
8.0.1 2026-01-25
8.0.0 2026-01-14
7.0.12 2025-09-21
7.0.11 2025-08-22
7.0.10 2025-05-27
7.0.9 2025-04-19
7.0.8 2025-02-23
7.0.7 2024-12-27
7.0.6 2024-11-11
7.0.5 2024-11-01
7.0.4 2024-10-23
7.0.3 2024-10-10
7.0.2 2024-08-18
7.0.1 2024-08-14
7.0.0 2024-08-03
6.0.14 2024-07-07
6.0.13 2024-07-06
6.0.12 2024-06-29
6.0.11 2024-05-04
6.0.10 2024-05-04
6.0.9 2024-04-21
6.0.8 2024-03-31
6.0.7 2024-03-17
6.0.6 2024-03-13
6.0.5 2024-02-19
6.0.4 2023-12-31
6.0.3 2023-12-15
6.0.2 2023-10-09
6.0.1 2023-09-18
6.0.0 2023-07-03
5.1.0 2023-06-01
5.0.2 2023-02-06
5.0.1 2023-01-28
5.0.0 2023-01-24
4.2.4 2022-07-08
4.2.3 2022-05-19
4.2.2 2022-02-05
4.2.1 2022-01-02
4.2.0 2021-12-27
4.1.0 2021-12-15
4.0.2 2021-12-13
4.0.1 2021-11-18
4.0.0 2021-09-17
3.0.2 2020-04-25
3.0.1 2020-04-25
3.0.0 2020-04-25
2.0.1 2018-09-18
2.0.0 2018-09-18
1.0.2 2018-07-13
1.0.1 2018-05-11
1.0.0 2018-05-08