> Markdown version of [/magazine/800-css-random-is-finally-available](https://www.wearedevelopers.com/magazine/800-css-random-is-finally-available). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # CSS random() Is Finally Available **By:** [Daniel Cranney](https://www.wearedevelopers.com/@daniel-cranney) **Published:** November 16, 2026 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. ![CSS random() and Custom properties](https://wearedevelopers.imgix.net//magazine/articles/800/images/content/nFvozpGoF6mUJmqUZBzX-1794214551.gif) ## 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](https://www.smashingmagazine.com/2026/10/embracing-playful-imperfection-css-random-function/). ## Related Articles - [Creating a 3D Card Fan with CSS Transforms](https://www.wearedevelopers.com/magazine/656-creating-a-3d-card-fan-with-css-transforms) - [Using light-dark() for Easy Theme Switching](https://www.wearedevelopers.com/magazine/630-using-light-dark-for-easy-theme-switching) - [CSS-Only Scroll-Driven Animations](https://www.wearedevelopers.com/magazine/712-css-only-scroll-driven-animations) - [Tweak CSS Properties Live with slideVars](https://www.wearedevelopers.com/magazine/733-tweak-css-properties-live-with-slidevars) ## Related Videos - [What’s New and What’s Next in Web UI](https://www.wearedevelopers.com/videos/956-what-s-new-and-what-s-next-in-web-ui) - [WeAreDevelopers LIVE - Is CSS Catching Up to Flash?](https://www.wearedevelopers.com/videos/2166-wearedevelopers-live-is-css-catching-up-to-flash) - [One Color to Rule Them All: Relative CSS Colors in Practice](https://www.wearedevelopers.com/videos/100016-one-color-to-rule-them-all-relative-css-colors-in-practice) - [Playing Games with CSS](https://www.wearedevelopers.com/videos/210-playing-games-with-css) ## Related Jobs - [Senior Product Engineer](https://www.wearedevelopers.com/jobs/48544-senior-product-engineer) at **Blacksmith Software** - [Senior Software Engineer, Angular (B2C Web Platform)](https://www.wearedevelopers.com/jobs/ext/3988925-senior-software-engineer-angular-b2c-web-platform) at **Bitpanda** - [Staff Frontend Design Engineer - AI & Systems Leader](https://www.wearedevelopers.com/jobs/ext/4629402-staff-frontend-design-engineer-ai-systems-leader) at **GitHub** - [Senior Engineer, Game Mathematician](https://www.wearedevelopers.com/jobs/48550-senior-engineer-game-mathematician) at **Sportradar Media Services GmbH** - [Senior Frontend Engineer](https://www.wearedevelopers.com/jobs/ext/4665402-senior-frontend-engineer) at **Almedia** - [Staff Product Engineer](https://www.wearedevelopers.com/jobs/48546-staff-product-engineer) at **Blacksmith Software**