
Company News
Socket Named to Rising in Cyber 2026 List of Top Cybersecurity Startups
Socket was named to the Rising in Cyber 2026 list, recognizing 30 private cybersecurity startups selected by CISOs and security executives.
@csstools/postcss-random-function
Advanced tools
npm install @csstools/postcss-random-function --save-dev
PostCSS Random Function lets you use the random function, following the CSS Values 5 specification.
div {
color: oklch(0.7 0.2 random(120deg, 240deg));
}
div {
color: oklch(0.7 0.2 random(120deg, 240deg, 7deg));
}
div {
margin: random(10px, 100px) random(10px, 100px);
padding: random(--padding, 10px, 100px) random(--padding, 10px, 100px);
}
/* becomes */
div {
color: oklch(0.7 0.2 177.17235deg);
}
div {
color: oklch(0.7 0.2 176deg);
}
div {
margin: 41.7525px 70.01679px;
padding: 44.03856px 44.03856px;
}
[!NOTE] Generated values are deterministic pseudo random numbers. Generating values twice with the same input will give the same result. The input length of the CSS source file is used as a random seed.
Add PostCSS Random Function to your project:
npm install postcss @csstools/postcss-random-function --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssRandomFunction = require('@csstools/postcss-random-function');
postcss([
postcssRandomFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
Given the dynamic nature of custom properties it's impossible to know what the variable value is, which means the plugin can't compute a final value for the stylesheet.
Because of that, any usage that contains a var is skipped.
The preserve option determines whether the original notation
is preserved. By default, it is not preserved.
postcssRandomFunction({ preserve: true })
div {
color: oklch(0.7 0.2 random(120deg, 240deg));
}
div {
color: oklch(0.7 0.2 random(120deg, 240deg, 7deg));
}
div {
margin: random(10px, 100px) random(10px, 100px);
padding: random(--padding, 10px, 100px) random(--padding, 10px, 100px);
}
/* becomes */
div {
color: oklch(0.7 0.2 177.17235deg);
color: oklch(0.7 0.2 random(120deg, 240deg));
}
div {
color: oklch(0.7 0.2 176deg);
color: oklch(0.7 0.2 random(120deg, 240deg, 7deg));
}
div {
margin: 41.7525px 70.01679px;
margin: random(10px, 100px) random(10px, 100px);
padding: 44.03856px 44.03856px;
padding: random(--padding, 10px, 100px) random(--padding, 10px, 100px);
}
FAQs
Use the random function in CSS
The npm package @csstools/postcss-random-function receives a total of 1,626,774 weekly downloads. As such, @csstools/postcss-random-function popularity was classified as popular.
We found that @csstools/postcss-random-function demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.

Company News
Socket was named to the Rising in Cyber 2026 list, recognizing 30 private cybersecurity startups selected by CISOs and security executives.

Research
Socket detected 84 compromised TanStack npm package artifacts modified with suspected CI credential-stealing malware.

Security News
A dispute over fsnotify maintainer access set off supply chain alarms around one of Go’s most widely used filesystem libraries.