[csswg-drafts] [css-values-5] Make specifying limits more convenient in random function (#13457)

Crissov has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values-5] Make specifying limits more convenient in random function ==
Order of minimum and maximum
-----

For the two mandatory `<calc-sum>` parameters of `random()`, [the spec](https://drafts.csswg.org/css-values-5/#random) currently says:

> If the maximum value is less than the minimum value, it behaves as if it’s equal to the minimum value.

However, it does not clearly say which limit comes first – _min_ apparently – and I don’t think it needs to because browsers could simply use the smaller computed value as _min_ and the larger as _max_. For values using (different) relative units, authors may not know in advance which one will compute to a smaller canonical value. 

For [`clamp()`](https://drafts.csswg.org/css-values/#comp-func) in comparison, there is a note explaining that arbitrary order of _min_ and _max_ needs explicit `min()` (first) and `max()` (last) with repeating the two values as their arguments, because that would be “matching CSS conventions elsewhere”, but I’m not sure which precedents exactly this refers to. 

Default minimum 
-------

For author convenience, I also believe that the minimum should be optional and default to zero or `0`. 

If it is left out then, a step value could not be provided because two values would be ambiguous. This could be solved if the comma between _min_ and _max_ was removed:

~~~~ ebnf
<random()> = random( <random-value-sharing>? , <calc-sum>? <calc-sum> , <calc-sum>? )
~~~~

The comma after the optional flag `<random-value-sharing>` is also not strictly necessary, since that is never a numeric value – or at least not alone: `fixed <number [0, 1]>` is currently specified as a possible value. I do not feel strongly about that, though. 

Note that in Level 4, the syntax of all math functions is collected in a [separate section](https://drafts.csswg.org/css-values/#calc-syntax) and the prose uses a more human-readable format like `clamp(MIN, VAL, MAX)` or `round(<rounding-strategy>?, A, B?)`. This suggests that the textual description in Level 5 could use `random(<random-value-sharing>?, MIN? || MAX, STEP?)` when it has stopped being a delta spec. (Perhaps it should be `round(<…>?, VAL, STEP?)` as well.)

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/13457 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 5 February 2026 08:50:52 UTC