DEV Community

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

Posted on • Edited on • Originally published at ekumedia.netlify.app

๐Ÿ” 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/[email protected]/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 copy(3, var-title)")
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/[email protected]/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.