⚡ Creating Custom Functions in FSCSS (Yes, CSS Can Do This)

⚡ Creating Custom Functions in FSCSS (Yes, CSS Can Do This)

Leader posted Originally published at dev.to 1 min read

One thing about FSCSS is that you can define your own functions… inside your styles. Here’s a simple example of how that works.

Custom randint Function

@define randint(array){
@random(@use(array)) 
} 

What this function does:

  • Takes an array as an argument.
  • Returns a random value directly from that array.

Step 1: Defining Arrays
First, we set up our possible values:

@arr sizes[ 100px, 150px, 200px ] 

Step 2: Using the Function
We call our custom function and assign it to a variable:

$height: @randint(@arr.sizes); 

Now $height dynamically becomes either 100px, 150px, or 200px (randomly selected at compile).

Why This Is Interesting

  • Reusable Logic: You can create complex logic once and use it across your entire design system.
  • Dynamic Design Systems: Build layouts that feel organic and varied rather than static and repetitive.

Example Usage

Applying that logic to a class is straightforward:

.box { 
  height: $height; 
  width: $height; 
  background: #2c5364; 
} 

Every compile can produce a slightly different UI!

https://www.npmjs.com/package/fscss

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelskiverified - Apr 23

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelskiverified - Mar 19

Just completed another large-scale WordPress migration — and the client left this

saqib_devmorph - Apr 7

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9

Your Tech Stack Isn’t Your Ceiling. Your Story Is

Karol Modelskiverified - Apr 9
chevron_left

Related Jobs

Commenters (This Week)

2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!