Skip to content

Fix random() CSS value documentation#44544

Open
ayshgoyl wants to merge 6 commits into
mdn:mainfrom
ayshgoyl:fix-random-css-doc
Open

Fix random() CSS value documentation#44544
ayshgoyl wants to merge 6 commits into
mdn:mainfrom
ayshgoyl:fix-random-css-doc

Conversation

@ayshgoyl

Copy link
Copy Markdown

Description

Updates the random() CSS function documentation to align with the latest CSS Values & Units specification. Replaces the obsolete element-shared model with the new cache key type system (element, property, and property-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

  • Replaces all references to the deprecated element-shared keyword.
  • Documents the element, property, and property-index cache key types.
  • Updates syntax, parameter descriptions, and behavior explanations to match the latest specification.
  • Adds examples covering cross-property linking, shorthand index scoping, and cache key sharing behavior.

Related issues and pull requests

Fixes #44502

@ayshgoyl ayshgoyl requested a review from a team as a code owner June 22, 2026 10:02
@ayshgoyl ayshgoyl requested review from hamishwillee and removed request for a team June 22, 2026 10:02
@github-actions github-actions Bot added Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed labels Jun 22, 2026
@hamishwillee

Copy link
Copy Markdown
Collaborator

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

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Preview URLs (1 page)

(comment last updated: 2026-06-26 05:22:47)

ayshgoyl and others added 5 commits June 23, 2026 15:59
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>
@bramus

bramus commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  • Documents the element, property, and property-index cache key types.

These are wrong. The values are element-scoped, property-scoped, and property-index-scoped, as per spec.

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

@hamishwillee hamishwillee Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment on lines +156 to +159
margin: random(property-index, 5px, 30px)
random(property-index, 5px, 30px)
random(property-index, 5px, 30px)
random(property-index, 5px, 30px);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
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);

Comment on lines 221 to 226
#### 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
#### 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 {

Comment on lines +412 to +415
margin: random(property-index, 5px, 40px)
random(property-index, 5px, 40px)
random(property-index, 5px, 40px)
random(property-index, 5px, 40px);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[markdownlint] reported by reviewdog 🐶
error MD033/no-inline-html Inline HTML [Element: random-value-sharing]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The syntax for CSS random() is out-of-date

4 participants