---
title: "Rolling the Dice with CSS random()"
description: "CSS is gaining a native `random()` function, now available in Safari Technology Preview, with the signature `random(min, max, step)` where all arguments share a unit type and the optional step rounds results."
url: "https://swe.quest/articles/rolling-the-dice-with-css-random-5c437898e1aae927"
canonical: "https://webkit.org/blog/17285/rolling-the-dice-with-css-random/"
source: "WebKit"
published: "2025-08-21"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["css","browsers","frontend"]
---

# Rolling the Dice with CSS random()

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2025-08-21, 9 min read, How-to. Original: [https://webkit.org/blog/17285/rolling-the-dice-with-css-random/](https://webkit.org/blog/17285/rolling-the-dice-with-css-random/)

## Summary

CSS is gaining a native \`random()\` function, now available in Safari Technology Preview, with the signature \`random(min, max, step)\` where all arguments share a unit type and the optional step rounds results. Because custom properties act like text substitution, reusing a random value needs a named ident (e.g. \`random(--size, 1px, 7px)\`) to share it across properties on one element, while \`element-shared\` shares a property's value across all matched elements, and the two can be combined. Demos include a star field, random grid placement, tossed photo stacks and a spinning wheel animation, all without JavaScript. The spec is still under CSS Working Group discussion and WebKit is asking developers for feedback.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [CSS](https://swe.quest/tags/css.md) (Web & mobile)
- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)

## Prerequisites

- CSS custom properties ([easy posts on CSS](https://swe.quest/tags/css.md?difficulty=easy))
- CSS animations and keyframes ([easy posts on CSS](https://swe.quest/tags/css.md?difficulty=easy))

## Keywords

CSS random(), Safari Technology Preview, WebKit, element-shared, CSS Working Group

## Related posts

- [WebKit Features for Safari 26.5](https://swe.quest/articles/webkit-features-for-safari-26-5-9e2dcf5e05a5b2cd.md): WebKit · 2026-05-11 · Medium · 11 min read · Browsers, CSS, Frontend
  Safari 26.5 adds the CSS :open pseudo-class for styling open \<details\>, \<dialog\>, \<select\> and \<input\> pickers, an element-scoped keyword for CSS random() after the spec changed named random values to be global by default, color-interpolation="linearRGB" for SVG gradients, ToggleEvent.source for identifying a popover's invoker, and the Origin API for structured origin and same-site comparisons without the Public Suffix List.
- [New to the web platform in August](https://swe.quest/articles/new-to-the-web-platform-in-august-d903fac59867da54.md): web.dev · 2026-08-28 · Easy · 5 min read · Browsers, CSS, JavaScript, Frontend
  Chrome 152 and Firefox 154 shipped to stable in August 2026, making several features Baseline Newly available: the text-box-trim/text-box-edge properties for trimming font leading, the sibling-count() and sibling-index() CSS functions, and the global autocorrect attribute.
- [Never too late for Firefox 88](https://swe.quest/articles/never-too-late-for-firefox-88-69478850ac7be10f.md): Mozilla Hacks · 2021-04-19 · Medium · 3 min read · Browsers, CSS, JavaScript, Frontend
  Firefox 88 adds the CSS :user-valid and :user-invalid pseudo-classes, which apply form validity styling only after the user leaves a field.
- [New to the web platform in June](https://swe.quest/articles/new-to-the-web-platform-in-june-7816d4d94fd092d9.md): web.dev · 2026-06-30 · Easy · 4 min read · Browsers, CSS, Frontend, Accessibility
  Chrome 149, Chrome 150 and Firefox 152 reached stable in June 2026.
- [New to the web platform in September](https://swe.quest/articles/new-to-the-web-platform-in-september-cc84fc5fb8499b25.md): web.dev · 2026-10-02 · Easy · 7 min read · Browsers, CSS, JavaScript, Frontend
  September 2026 brought Chrome 153 and 154, Firefox 155 through 157, and Safari 27 to stable, the first month of bi-weekly Chrome and Firefox releases.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
