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>
โ
Output:
h2::before {
content: 100 100 100 100 100 100 100 100 100 100 100 100 100;
}
๐ก 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>
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.