Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@csstools/postcss-color-mix-function
Advanced tools
@csstools/postcss-color-mix-function is a PostCSS plugin that allows you to use the CSS `color-mix()` function in your stylesheets. This function enables you to mix two colors together, which can be useful for creating color themes, gradients, and other visual effects.
Mixing Two Colors
This feature allows you to mix two colors together using the `color-mix()` function. In this example, red and blue are mixed in equal proportions to produce a purple color.
/* Input CSS */
.example {
color: color-mix(in srgb, red 50%, blue);
}
/* Output CSS */
.example {
color: #800080;
}
Mixing Colors with Different Percentages
This feature allows you to specify different percentages for each color in the mix. In this example, red is given a 70% weight and blue a 30% weight, resulting in a reddish-purple color.
/* Input CSS */
.example {
color: color-mix(in srgb, red 70%, blue 30%);
}
/* Output CSS */
.example {
color: #b3004d;
}
Using Different Color Spaces
This feature allows you to mix colors in different color spaces. In this example, the colors are mixed in the LCH color space, which can produce different results compared to the default sRGB color space.
/* Input CSS */
.example {
color: color-mix(in lch, red 50%, blue);
}
/* Output CSS */
.example {
color: #a2007d;
}
The `postcss-color-function` package allows you to use color functions like `color()` in your CSS. It provides similar functionality to `@csstools/postcss-color-mix-function` but focuses on a broader range of color manipulations, not just mixing.
The `postcss-preset-env` package includes a variety of modern CSS features, including color manipulation functions. It is more comprehensive than `@csstools/postcss-color-mix-function` as it aims to polyfill many CSS features, not just color mixing.
The `postcss-advanced-variables` package allows you to use Sass-like variables and functions in your CSS, including color functions. It provides a broader set of features for CSS preprocessing compared to the more focused `@csstools/postcss-color-mix-function`.
PostCSS Color Mix Function lets you use the color-mix()
function following the CSS Color 5 Specification.
.purple_plum {
color: color-mix(in lch, purple 50%, plum 50%);
}
/* becomes */
.purple_plum {
color: rgb(175, 92, 174);
}
Add PostCSS Color Mix Function to your project:
npm install postcss @csstools/postcss-color-mix-function --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssColorMixFunction = require('@csstools/postcss-color-mix-function');
postcss([
postcssColorMixFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
PostCSS Color Mix Function 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.
postcssColorMixFunction({ preserve: true })
.purple_plum {
color: color-mix(in lch, purple 50%, plum 50%);
}
/* becomes */
.purple_plum {
color: rgb(175, 92, 174);
color: color-mix(in lch, purple 50%, plum 50%);
}
FAQs
Use the color-mix function in CSS
The npm package @csstools/postcss-color-mix-function receives a total of 792,304 weekly downloads. As such, @csstools/postcss-color-mix-function popularity was classified as popular.
We found that @csstools/postcss-color-mix-function 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.