Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@csstools/postcss-contrast-color-function

csstools581.8kMIT-02.0.12TypeScript support: included

Dynamically specify a text color with adequate contrast

contrast, contrast-color, css, postcss-plugin, wcag

readme

PostCSS Contrast Color Function PostCSS Logo

npm install @csstools/postcss-contrast-color-function --save-dev

PostCSS Contrast Color Function lets you dynamically specify a text color with adequate contrast following the CSS Color 5 Specification.

.color {
    color: contrast-color(oklch(82% 0.2 330));
}

/* becomes */

.color {
    color: rgb(0, 0, 0);
    color: contrast-color(oklch(82% 0.2 330));
}

Usage

Add PostCSS Contrast Color Function to your project:

npm install postcss @csstools/postcss-contrast-color-function --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssContrastColorFunction = require('@csstools/postcss-contrast-color-function');

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

Options

preserve

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

postcssContrastColorFunction({ preserve: false })
.color {
    color: contrast-color(oklch(82% 0.2 330));
}

/* becomes */

.color {
    color: rgb(0, 0, 0);
}

changelog