Fix random() CSS value documentation#44544
Conversation
|
Thanks @ayshgoyl . @bramus Would you like to give this a technical review? We will also need an update to https://github.com/mdn/browser-compat-data/blob/main/css/types/random.json in order to reflect the new properties |
|
Preview URLs (1 page) (comment last updated: 2026-06-26 05:22:47) |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
These are wrong. The values are If you could fix that upfront, I can take a look later. |
| To instead scope the custom key per element while still linking properties within each element, use `element` as the cache key type: | ||
|
|
||
| ```css | ||
| ````css |
There was a problem hiding this comment.
It's always three backticks.
The flaw predates you - see line 202.
You need to rever to 3 backticks, move the text on 202 to its own line, and remove the backtics on line 205.
Go though and revert anywhere you added an extra backtick and check how rendering looks.
It is much easier to preview this stuff live using - have you run it locally using npm run start?
There was a problem hiding this comment.
PS when you think this is ready for another review, please ping Bramus. I'll look properly at the end when it is technically correct. Thanks!
| margin: random(property-index, 5px, 30px) | ||
| random(property-index, 5px, 30px) | ||
| random(property-index, 5px, 30px) | ||
| random(property-index, 5px, 30px); |
There was a problem hiding this comment.
[mdn-linter] reported by reviewdog 🐶
| margin: random(property-index, 5px, 30px) | |
| random(property-index, 5px, 30px) | |
| random(property-index, 5px, 30px) | |
| random(property-index, 5px, 30px); | |
| margin: random(property-index, 5px, 30px) random(property-index, 5px, 30px) | |
| random(property-index, 5px, 30px) random(property-index, 5px, 30px); |
| #### Automatic behavior | ||
|
|
||
| When the first parameter is omitted, or explicitly set to `auto`, an ident is auto-generated from the property name and position. This behavior can cause some unexpected random base value sharing. | ||
| When the first parameter is omitted, or explicitly set to `auto`, a key is auto-generated from the property name and position index within the value. This behavior can cause some unexpected random base value sharing. | ||
|
|
||
| ```css | ||
| .foo { |
There was a problem hiding this comment.
[mdn-linter] reported by reviewdog 🐶
| #### Automatic behavior | |
| When the first parameter is omitted, or explicitly set to `auto`, an ident is auto-generated from the property name and position. This behavior can cause some unexpected random base value sharing. | |
| When the first parameter is omitted, or explicitly set to `auto`, a key is auto-generated from the property name and position index within the value. This behavior can cause some unexpected random base value sharing. | |
| ```css | |
| .foo { | |
| #### Automatic behavior When the first parameter is omitted, | |
| or explicitly set to `auto`, | |
| a | |
| key | |
| is | |
| auto-generated | |
| from | |
| the | |
| property | |
| name | |
| and | |
| position | |
| index | |
| within | |
| the | |
| value. | |
| This | |
| behavior | |
| can | |
| cause | |
| some | |
| unexpected | |
| random | |
| base | |
| value | |
| sharing. | |
| ```css | |
| .foo { |
| margin: random(property-index, 5px, 40px) | ||
| random(property-index, 5px, 40px) | ||
| random(property-index, 5px, 40px) | ||
| random(property-index, 5px, 40px); |
There was a problem hiding this comment.
[mdn-linter] reported by reviewdog 🐶
| margin: random(property-index, 5px, 40px) | |
| random(property-index, 5px, 40px) | |
| random(property-index, 5px, 40px) | |
| random(property-index, 5px, 40px); | |
| margin: random(property-index, 5px, 40px) random(property-index, 5px, 40px) | |
| random(property-index, 5px, 40px) random(property-index, 5px, 40px); |
| ## Description | ||
|
|
||
| The `random(SEED, MIN, MAX, STEP)` function specifies the minimum and maximum values and optional step increments, starting at the minimum value. The function generates a random result within the range specified. The seed, an [optional `<random-value-sharing>`](#random-value-sharing) parameter, enables sharing or varying random base values across different properties and elements. | ||
| The `random([<random-value-sharing>,] MIN, MAX[, STEP])` function specifies the minimum and maximum values and optional step increments, starting at the minimum value. The function generates a random result within the range specified. The optional [<random-value-sharing>](#random-value-sharing) parameter controls whether and how random base values are shared across properties and elements. |
There was a problem hiding this comment.
[markdownlint] reported by reviewdog 🐶
error MD033/no-inline-html Inline HTML [Element: random-value-sharing]
Description
Updates the
random()CSS function documentation to align with the latest CSS Values & Units specification. Replaces the obsoleteelement-sharedmodel with the new cache key type system (element,property, andproperty-index), expands parameter documentation, and adds examples demonstrating the new random value sharing behavior.Motivation
The existing documentation reflects an outdated version of the specification and no longer describes the current random value sharing model. This update improves accuracy, clarifies how random base values are scoped and shared, and provides practical examples to help developers understand and use the new cache key types correctly.
Additional details
element-sharedkeyword.element,property, andproperty-indexcache key types.Related issues and pull requests
Fixes #44502