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

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

1 9
calendar_todayschedule1 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:
```scss
.box { 
  height: $height; 
  width: $height; 
  background: #2c5364; 
} 

Every compile can produce a slightly different UI!

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

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

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

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

Karol Modelskiverified - Apr 9

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

Dharanidharan - Feb 9
chevron_left
805 Points11 Badges
4Posts
2Comments
3Connections
A full-stack web developer: Building smart solutions, designing meaningful experiences, and continuo... Show more

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!