Why CSS Fought Randomness

CSS is declarative and deterministic, and both traits cut against natural variation. Declarative means the language describes the what rather than the how; deterministic means a given input always produces the same output. Specify red and you get red. This is intentional, and it is what makes the layout engine predictable: if you understand it, you can say exactly which styles apply at any moment. The same property that makes CSS reliable also blocks generated content.

The Improvised Solutions

Fake variation with selectors and animation

Patterns built from :nth-child() selectors, or animation tricks, can look irregular for a while. Nothing about them is random: the output is fixed, and the pattern eventually shows. A person may not guess the next value without effort; a machine can.

Animated illustrated of five numbered cards swapping positions with the first card moving toward the back in succession.
Credit: Alvaro Montoro

Preprocessor math, frozen at build time

Sass, SCSS, Less and similar tools ship math modules with random functions, but those run at compilation time. Values are generated once and then locked until the next build. Every visitor and every refresh sees the same numbers. This was a small step, not a solution.

Generating values on the server

Server-side languages such as PHP, Java and ASP can produce random values while rendering HTML or CSS. Each page load brings fresh values, and you control the randomization by writing the functions yourself. The catch: content added to the page dynamically keeps the values fixed at first load. That limitation grew sharper as single-page applications and client-side JavaScript architectures spread.

JavaScript delivers, at a cost

Moving randomness into JavaScript finally produced genuine variation — on creation, on refresh and on mutation. Frameworks, CSS-in-JS libraries and plain vanilla code all get there, with some performance and complexity concerns. For the first time styles behaved naturally. The randomization simply lived outside of CSS.

The Mismatch

Two problems remain with the JavaScript approach:

  • It answers a declarative question with an imperative tool.
  • It moves layout decisions out of CSS and into JavaScript.

CSS handles layout; JavaScript handles logic. Solving a CSS limitation by pushing layout decisions into JavaScript works, but it breaks the model, and that is the source of the faint "this isn't quite right" feeling even when the page functions correctly.

The Native Fix

The correction is to move randomization into CSS itself — to solve a layout problem in the layout layer. The CSS Values and Units Module Level 5 introduces two functions for it:

  • random() generates a random value between a minimum and a maximum.
  • random-item() selects a random value from a given list.
Showing a CSS code snippet of the random and random-item functions.

Least Power, Better Fit

Native randomness also follows the Rule of Least Power: use the least powerful language that can express and solve the problem. That language is usually the best suited to the task, since its features match the level at which they apply and stay simpler, more efficient and better performing. A more powerful language can do the job, but it adds abstraction and complexity.

On the web platform, HTML handles structure, CSS handles styling and layout, and JavaScript is the more powerful layer. Putting randomization in CSS moves the solution to the right layer. That is part of why these features matter more than most additions.

What Changes

CSS has always been deterministic by design, and native randomness breaks with that tradition. For the first time, CSS models natural systems with variation directly — no hacks, no tooling, no outsourcing. That enables generative layouts, organic patterns, playful micro-interactions and design systems that feel alive, while restoring architectural clarity so each web layer does its intended job.

The language shifts from purely stylistic toward a generative layout system: CSS stops being a passive actor and becomes an active participant in rendering, defining a space of possible outcomes that the browser resolves into a concrete page. The point is not merely that things look different, but that the platform becomes more coherent and expressive — and that a long-overlooked corner of CSS can reshape what we imagine is possible on the web.