There was a time when CSS felt… predictable.
Every color was chosen.
Every position was fixed.
Every animation behaved exactly the same—every single time.
Then came FSCSS… and suddenly, randomness became a design tool.
What is @random() in FSCSS?
The @random() function in Figured Shorthand Cascading Style Sheets (FSCSS) allows you to generate dynamic, non-deterministic values at runtime.
Instead of hardcoding styles, you let the browser decide—from a list you provide.
color: @random([red, blue, green]);
Each render can produce a different result. Same code, different vibe.
How It Works
@random() accepts an Array of values and randomly selects one.
Numbers
width: @random([100, 200, 300])px;
Colors
background: @random([lightgreen, yellow, orange]);
Transforms
transform: translateX(@random([10, 30, 40, -60])px);
Why This Matters
Traditional CSS is static.
FSCSS introduces controlled randomness.
That opens doors to:
Procedural UI design
Organic-looking animations
Dynamic backgrounds (stars, particles, noise)
Unique user experiences on every load
Real-World Use Cases
- Randomized Star Field
.star{
left: @random([10,20,30,40,50,60,70,80,90])%;
top: @random([10,20,30,40,50,60,70,80,90])%;
}
- Dynamic Button Colors
.btn{
background: @random([#ff6b6b, #6bcB77, #4d96ff, #ffd93d]);
}
- Organic Motion
@keyframes float{
to{
transform: translateY(@random([-20, -40, -60])px);
}
}
Best Practices
Use CDN runtime when working with @random() (it runs in the browser).
Combine with:
@arr → reusable value sets
@define → reusable logic blocks
@event → conditional styling
Avoid overusing randomness in critical UI elements (keep UX predictable where needed).
A Quick Note
Random doesn’t mean chaos.
Good design still needs constraints.
Think of @random() as guided creativity, not pure unpredictability.
Final Thoughts
@random() is one of those features that quietly changes how you think about CSS.
It’s no longer just styling it’s behavior.
And once you start using it…
you’ll wonder why CSS was ever fully static.
Top comments (0)