Smashing Magazine Explores CSS Random Function
Smashing Magazine discusses the new CSS random() function, which brings imperfection to the web without JavaScript libraries. The function generates pseudo-random values in CSS, allowing for playful and organic designs.
Original reporting · smashingmagazine.com
Original: “Embracing Playful Imperfection With The CSS `random()` Function”
Read “Embracing Playful Imperfection With The CSS `random()` Function” at Smashing Magazine →
How this was written. Awesome B2B Design wrote this article with a language model from Smashing Magazine’s reporting (model: @cf/meta/llama-3.3-70b-instruct-fp8-fast); it describes that reporting rather than adding to it. The original, linked above, is the full story.
Key points from Smashing Magazine’s report
- The CSS random() function generates pseudo-random values in CSS, allowing for playful and organic designs.
- The function is currently supported in Safari and is rolling out in Chrome 156.
- Caching keys can be used to ensure multiple properties share the same random value, maintaining consistency in designs.
- The function supports stepping and rounding, which can be helpful in creating grid-based designs.
- Designers can use the @supports feature to test the CSS random() function and provide a fallback for older browsers.
Design systems typically prioritize consistency, but the CSS random() function introduces a new element of randomness. According to Smashing Magazine, this function can add a touch of imperfection to the web, making it feel more alive and human.
The CSS random() function is specified in CSS Values and Units Module Level 5 and generates a pseudo-random value inside CSS without needing JavaScript or a build-time Sass loop. Smashing Magazine reported that the function is currently supported in Safari and is rolling out in Chrome 156.
The function's syntax allows for comma-separated arguments, including a random-caching-key, minimum and maximum bounds, and an optional step size. For example, rotate: random(-3deg, 3deg) generates a random angle between -3deg and 3deg.
One of the key features of the CSS random() function is the ability to use caching keys, which allow multiple properties to share the same random value. This ensures that elements remain consistent, even when using random values. Smashing Magazine demonstrated this feature with an example of a box that sets inline-size and block-size at random, but remains a perfect square.
The CSS random() function also supports stepping and rounding, which can be helpful in cases where designers want elements to jump around a bit, but still land on a pre-defined grid. For instance, top: random(0px, 60px, 15px) only produces values of 0px, 15px, 30px, 45px, or 60px.
To test the CSS random() function, designers can use the @supports feature, which allows them to wrap their experiments in a conditional statement. This ensures that the function only applies to browsers that support it, providing a fallback for older browsers.
Smashing Magazine created several demos to showcase the potential of the CSS random() function, including organic typography, bouncing letters, and splayed cards. These demos demonstrate how the function can be used to create unique and engaging designs.
Questions and answers
What is the CSS random() function?
The CSS random() function generates a pseudo-random value inside CSS without needing JavaScript or a build-time Sass loop.
How do I use caching keys with the CSS random() function?
Caching keys can be used by referencing the same key in multiple properties, ensuring that they share the same random value.
Which browsers support the CSS random() function?
The function is currently supported in Safari and is rolling out in Chrome 156, with positive signals from Mozilla on Firefox.



