PostCSS plugin to change text color depending on background color contrast. This is generally useful if your writing a mixin or placeholder selector that applies to many scenarios.
TL;DR Use the contrast() function
anywhere and get #fff or #000 depending on the lightness of the color you
pass in the function.
npm i --save-dev postcss-contrast:root {
--bg-color: #fff;
}
body {
background-color: var(--bg-color);
color: contrast(var(--bg-color));
}body {
background-color: #fff;
color: #000;
}var postcss = require('postcss');
var contrast = require('postcss-contrast');