Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@csstools/postcss-relative-color-syntax
Advanced tools
@csstools/postcss-relative-color-syntax is a PostCSS plugin that allows you to use relative color syntax in your CSS. This can simplify color manipulations and make your stylesheets more maintainable by enabling relative color adjustments directly in your CSS.
Relative Color Syntax
This feature allows you to use relative color syntax to mix colors directly in your CSS. The example shows how to mix white and black to get a gray background color.
/* Input CSS */
body {
background-color: color-mix(in srgb, white 50%, black);
}
/* Output CSS */
body {
background-color: #808080;
}
Color Adjustments
This feature allows you to adjust colors based on contrast. The example shows how to set a button's background color to blue while ensuring it contrasts well with both white and black.
/* Input CSS */
button {
background-color: color-contrast(white vs black, blue);
}
/* Output CSS */
button {
background-color: #0000ff;
}
postcss-color-function is a PostCSS plugin that allows you to use color functions like color() in your CSS. It provides similar functionality to @csstools/postcss-relative-color-syntax but focuses more on the color() function and its capabilities.
postcss-preset-env is a PostCSS plugin that allows you to use future CSS features today. It includes a variety of plugins, including those for color manipulation, making it a more comprehensive solution compared to @csstools/postcss-relative-color-syntax.
PostCSS Relative Color Syntax lets you use the relative color syntax in CSS color functions following CSS Color Module 5.
.example {
background: oklab(from oklab(54.3% -22.5% -5%) calc(1.0 - l) calc(a * 0.8) b);
}
/* becomes */
.example {
background: rgb(12, 100, 100);
}
Add PostCSS Relative Color Syntax to your project:
npm install postcss @csstools/postcss-relative-color-syntax --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssRelativeColorSyntax = require('@csstools/postcss-relative-color-syntax');
postcss([
postcssRelativeColorSyntax(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
PostCSS Relative Color Syntax runs in all Node environments, with special instructions for:
The preserve
option determines whether the original notation
is preserved. By default, it is not preserved.
postcssRelativeColorSyntax({ preserve: true })
.example {
background: oklab(from oklab(54.3% -22.5% -5%) calc(1.0 - l) calc(a * 0.8) b);
}
/* becomes */
.example {
background: rgb(12, 100, 100);
background: oklab(from oklab(54.3% -22.5% -5%) calc(1.0 - l) calc(a * 0.8) b);
}
FAQs
Use the relative color syntax in CSS
The npm package @csstools/postcss-relative-color-syntax receives a total of 812,855 weekly downloads. As such, @csstools/postcss-relative-color-syntax popularity was classified as popular.
We found that @csstools/postcss-relative-color-syntax 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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.