DEV Community

Cover image for πŸ” FSCSS rpt() and re(): Repeating Styles Intelligently
FSCSS tutorial for FSCSS tutorial

Posted on • Edited on • Originally published at fscss.onrender.com

πŸ” FSCSS rpt() and re(): Repeating Styles Intelligently

Learn how FSCSS uses rpt() to repeat strings and re() to replace them, making CSS smarter and faster to write.


Welcome to Part 2 of our FSCSS series!

In this post, we’ll explore the rpt() and re() methods introduced in FSCSS v1.1.6 β€” designed to repeat values and replace tokens efficiently in your CSS workflow.


πŸ“¦ What Is rpt()?

rpt(count, text) is a shorthand function that repeats any string a given number of times.

βœ… It's especially useful for repeating numbers, symbols, or classnames without writing them manually.


πŸ§ͺ Example: Repeat and Replace in One Shot

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

<h2></h2>

<style>
/* Repeat '100 ' thirteen times and assign to $no */
$no: " RPT(13, '100 ')";

/* Replace 'Text' with 'content' */
Re(Text, 'content')

H2:before {
  Text: $no!;
}
</style>
Enter fullscreen mode Exit fullscreen mode

βœ… Output:

h2::before {
  content: 100 100 100 100 100 100 100 100 100 100 100 100 100;
}
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Use Cases for rpt() in CSS

  • ⏱ Repeating animations or delays

  • πŸ”’ Multiplying numeric values like 100, 1em, or --var1

  • 🎯 Repeating icon symbols or decorative elements


πŸ” Combined Power with re()

re(search, replace) lets you rename or substitute style keywords, enabling you to define patterns like:

Re(title-color: "#f55")
Re(Text, 'content')

Combined with rpt(), you can generate large sections of repeated or themed styles with just a few lines.


πŸš€ Try It in One Line

Just add this to your HTML:

<script src="https://cdn.jsdelivr.net/npm/fscss@1.1.6/e/exec.min.js" async></script>
Enter fullscreen mode Exit fullscreen mode

Then use FSCSS directly inside your <style> tags. No build step required!


🌐 FSCSS Resources

  • πŸ“˜ Full FSCSS Docs

  • πŸ“¦ npm install fscss

  • 🌐 ekumedia.netlify.app

✍️ Previous post: Intro to copy() and re() β†’


πŸ™Œ Credits

Writer: David-Hux
Publisher: Figsh
Series Host: You, the user πŸš€


➑️ Next up: We’ll dive into FSCSS variables, dynamic gradients, and mx() shorthand. Stay tuned and follow the series!

Drop a comment if you’ve built something with FSCSS!




Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.