CSS random() Is Finally Available
- Discuss this with your agent
- Open in Claude
- Open in ChatGPT
You can now generate random values in plain CSS. The random() function, from the CSS Values and Units Level 5 spec, has been in Safari since 26.2 and is rolling out in Chrome 156. No JavaScript, no Sass loop spitting out hundreds of lines of static styles.
The syntax is random(min, max, step), where the step is optional and snaps the result to fixed increments. Every element gets its own value.
The progressive enhancement approach
Declare a safe baseline first, then the random() version straight after it:
.card {
rotate: 0deg; /* baseline */
rotate: random(-4deg, 4deg, 0.5deg); /* enhancement */
translate: 0 0;
translate: 0 random(-6px, 6px, 1px);
}
A browser that doesn’t understand random() throws away the second declaration while parsing, so the baseline stands and the cards sit straight. A browser that does understand it uses the later declaration. Four cards, four slightly different tilts, and the values change on every page load. No @supports and no script.

The alternative: a custom property
If you need the effect in every browser today, a CSS custom property gets you the same result, with a few lines of JavaScript supplying the values:
.card {
rotate: var(--tilt, 0deg);
translate: 0 var(--lift, 0px);
}
document.querySelectorAll('.card').forEach((card) => {
card.style.setProperty('--tilt', `${(Math.random() * 8 - 4).toFixed(1)}deg`);
card.style.setProperty('--lift', `${(Math.random() * 12 - 6).toFixed(0)}px`);
});
It works everywhere and you can read the value back, but it adds a script to maintain, and cards can flash straight before they tilt.
Our advice
For decorative effects like this, lean into progressive enhancement. Browsers without random() still get a perfectly good page, support will only improve from here, and there is no workaround code to clean up later. Reach for the custom property only when the randomness really has to appear everywhere.
For more on where randomness works well (and where it doesn’t), see Brecht De Ruyte’s piece on Smashing Magazine.