DEV Community

Cover image for ๐Ÿš€ Stop Writing 100 Keyframes: Meet FSCSS Shorthands
FSCSS tutorial for FSCSS tutorial

Posted on

๐Ÿš€ Stop Writing 100 Keyframes: Meet FSCSS Shorthands

Wait, did I just see a CSS file with an array loop? ๐Ÿคฏ

If you've ever had to build a loading progress animation, a countdown, or a complex multi-step transition in pure CSS, you know the pain. You usually end up with a CSS file that is 500 lines of repetitive @keyframes.

Enter FSCSS (Figured Shorthand Cascading Style Sheet).


The "Magic" Array โœจ

In the example below, we aren't manually typing out 1%, 2%, 3%. Instead, we use a shorthand directive that the FSCSS compiler understands:

@arr numlist[count(99)]

@keyframes count {
  @arr.numlist[]% {
    content: 'ing...@arr.numlist[]%';
  } 
}
Enter fullscreen mode Exit fullscreen mode

This simple syntax generates 99 keyframes automatically. No copy-paste. No repetitive code. Just clean logic.


Why This is a Game Changer for Production ๐ŸŽฏ

While the browser doesn't natively speak @arr, the FSCSS CLI does. By running fscss style.fscss style.css, it compiles those few lines of logic into a standard, production-ready CSS file.

Benefit Description
Maintainability Change one line of logic instead of 100 keyframes
Performance Get smooth, GPU-accelerated CSS animations without the manual labor
Cleaner Source Your source files stay tiny and readable


See it in Action โšก๏ธ

Here's a live demo showing how a few lines of FSCSS shorthand creates a dynamic, frame-perfect loading sequence:

<script src="https://cdn.jsdelivr.net/npm/fscss@1.1.14/exec.min.js" async></script>

<style>
body{
  background: #121212;
  padding: 20px;
  color: #ddd;
}
h2:after{
  content: "...";
  animation: count 10s steps(100) forwards;
}

/* array of 1 to 99 */
@arr numlist[count(99)]

/* animation */
@keyframes count{
  /* downloading... */
  0%{
    content: 'ing...0%'
  } 

  /* looping */
  @arr.numlist[]%{
    content: 'ing...@arr.numlist[]%';
  } 

  /* 100% downloaded */
  100%{
    content: 'ed';
  }
}
</style>

<h2>Download</h2>
Enter fullscreen mode Exit fullscreen mode

Interactive Demo on CodePen


How to Use It in Your Workflow ๐Ÿ”ง

Ready to supercharge your CSS animations? Getting started takes just three steps:

  1. Install FSCSS
npm install -g fscss
Enter fullscreen mode Exit fullscreen mode
  1. Write Your .fscss File

Create a file with shorthand goodness:

@arr numbers[count(50)]

@keyframes pulse {
  @arr.numbers[]% {
    opacity: calc(@arr.numbers[] / 100);
    transform: scale(calc(1 + @arr.numbers[] / 200));
  }
}
Enter fullscreen mode Exit fullscreen mode
  1. Compile to CSS
fscss input.fscss output.css
Enter fullscreen mode Exit fullscreen mode

The Debate: Shorthands vs. Traditional ๐Ÿ’ญ

What do you think? Are CSS shorthands the future, or do you prefer sticking to standard pre-processors?

Pros of FSCSS:

ยท Drastically reduces code repetition
ยท Makes complex animations maintainable
ยท Compiles to standard CSS (no runtime overhead)

Traditional Approach:

ยท More explicit (some may find easier to debug)
ยท No compilation step needed
ยท Familiar to all CSS developers


https://github.com/Figsh/counterx.fscss/blob/main/README.md

Top comments (0)