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

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

●1 ●31 ●67
calendar_today • schedule1 min read
— Originally published at dev.to

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

Want more #webdev & #programming deep dives?

Join 6,173+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

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

Karol Modelski - Mar 19

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

saqib_devmorph - Apr 7

Frameworks Are Institutional Memory

Ken W. Algerverified - Sep 17

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

Karol Modelski - Apr 9
chevron_left
1.9k Points • 99 Badges
31Posts
20Comments
15Connections
A full-stack web developer: Building smart solutions, designing meaningful experiences, and continuo... Show more

Related Jobs

View all jobs →

Commenters (This Week)

13 comments
7 comments
6 comments

Contribute meaningful comments to climb the leaderboard and earn badges!