Firefox 161 shipped on 24 November 2026, and for CSS authors the standout change is support for the random() function. MDN’s browser compatibility data already listed it in Chrome 156 and Safari 26.2, so with Firefox on board, random values in pure CSS now work in current versions of all major browser engines. This guide explains the syntax, the part that trips people up (how random values are shared), and practical patterns with safe fallbacks.
What shipped in Firefox 161
From the Firefox 161 release notes for developers:
random()is supported. It generates a random value within a range, optionally snapped to a step size, and an optional<random-key>lets you share one random base value across functions, elements or properties.var(),attr()andenv()accept nested functions in their first parameter. For example,env(var(--safe-area-block-start))now works.
The same release adds the CSS Typed Object Model API, custom clipboard formats and Compression Dictionary Transport, but this post sticks to random().
Browser support
According to MDN’s compatibility data, the core function works in Chrome/Edge 156+, Safari 26.2+ and Firefox 161+. There’s one catch: the property-scoped and property-index-scoped keywords are listed for Safari 27.3, a newer version than the Safari 27.2 currently in release. Stick to auto, element-scoped, custom names and fixed if you need every current browser.
The syntax
The MDN reference for random() describes it as taking two to four comma-separated parameters:
random(<random-key>?, <min>, <max>, <step>?)
/* Basic */
width: random(100px, 300px);
rotate: random(0deg, 360deg);
/* Snapped to steps: 0, 45deg, 90deg ... 360deg */
rotate: random(0deg, 360deg, 45deg);
/* Mixed units are fine if the type matches (both lengths) */
margin-inline-start: random(1em, 40px);
Rules worth remembering:
- Min, max and step must resolve to the same data type: lengths, angles, times, numbers, percentages and so on. The units can differ.
- The result is inclusive of min and max.
- If max is less than min, the function returns the min value.
The tricky part: who shares a random value?
The first parameter, <random-key>, decides which random() calls get the same base value (the “seed”) and which get different ones.
| Key | Same value across elements? | Same value across properties? |
|---|---|---|
auto (default) |
No | No |
element-scoped |
No, each element differs | Yes, within one element |
property-scoped |
Yes | No, each property differs |
--my-name |
Yes, everywhere with that name | Yes |
fixed 0.5 |
You supply the seed (0 ≤ n < 1) | Yes |
Random squares: element-scoped
Want each card to be a square of a different size? Link width and height within each element, but vary across elements:
.tile {
width: random(--tile element-scoped, 60px, 160px);
height: random(--tile element-scoped, 60px, 160px);
}
One shared value everywhere: a custom name
.a, .b, .c {
width: random(--hero-size, 10px, 200px);
height: random(--hero-size, 10px, 200px);
}
All three become identical squares, because every call with --hero-size shares one base value.
Deterministic output: fixed
fixed <number> skips randomness and uses your number as the seed. It’s useful for tests, screenshots, or a value your server picks:
.banner {
/* Always resolves to the midpoint between 1em and 40vw */
inline-size: random(fixed 0.5, 1em, 40vw);
}
Gotcha: auto can share values unexpectedly
MDN warns that with auto (or no key), the browser generates a seed name from the property name and position. So:
.btn { width: random(100px, 200px); }
.btn:hover { width: random(100px, 200px); }
Both rules get the same generated name, so the width doesn’t change on hover. If you want independent values, give each random() call its own unique dashed name.
Gotcha: custom properties don’t store the result
A plain custom property behaves like text replacement:
:root { --random-angle: random(0deg, 360deg); }
Every var(--random-angle) becomes a new random() call. To compute a value once and reuse it, register the property with @property. Registered custom properties compute and store the random value:
@property --card-size {
syntax: "<length>";
inherits: true;
initial-value: random(100px, 200px);
}
.card {
width: var(--card-size);
height: var(--card-size);
}
Practical patterns
1. Organic confetti or particles
.confetti span {
position: absolute;
inset-inline-start: random(0%, 100%);
rotate: random(0deg, 360deg, 15deg);
animation: fall random(2s, 5s) linear infinite;
animation-delay: random(0s, 3s);
}
@keyframes fall {
from { translate: 0 -10vh; }
to { translate: 0 110vh; }
}
Each random() here uses auto, so every span and every property gets its own value.
2. Slightly “hand-placed” sticky notes
.note {
rotate: random(-4deg, 4deg, 1deg);
translate: random(-6px, 6px) random(-6px, 6px);
}
Snapping the rotation to whole degrees keeps the result tidy.
3. Staggered entrance without nth-child maths
.grid-item {
animation: pop-in 400ms ease-out both;
animation-delay: random(0ms, 600ms, 50ms);
}
Fallbacks with @supports
Browsers that don’t understand random() drop the whole declaration. Write a fixed value first, then layer on the random version. MDN’s own example tests support with order:
.note {
rotate: -2deg; /* fallback */
}
@supports (order: random(1, 2)) {
.note {
rotate: random(-4deg, 4deg, 1deg);
}
}
Accessibility and when not to use it
MDN points out that because you don’t control the exact value, random() can produce inaccessible results. A random text colour could have poor contrast, for example. Some guidelines:
- Randomise decoration (rotation, delay, position of ornaments), not text colour or font size.
- Combine motion with
@media (prefers-reduced-motion: reduce)and turn animations off there. - Don’t use it for anything that must match between server and client, or between users. Use
fixedor set the value from your backend instead.
Takeaway
With Firefox 161, random() moves from experiment to a tool you can use in production for decorative variety. Learn the <random-key> options (element-scoped for per-element linking, a --name for global sharing, fixed for determinism), register custom properties when you need a stored value, and always ship a static fallback inside @supports.
