Looping in CSS preprocessors and template engines

Loops aren't something you reach for every day, but when the need appears, it helps that preprocessors can handle them — plain HTML and CSS can't. A reference guide walks through loop support across several tools.

Sass (SCSS)

Sass' SCSS syntax covers all three loop forms: for, while and each.

Less

Less also provides for, while and each loops. Its when clause stands in for a while condition.

Stylus

Stylus has only for loops — no other form is available. Since its for behaves much like an each loop, the guide includes a clearer each-style example alongside it. CSS-Tricks star logo

Pug, Haml and Slim

All three template engines support for, while and each loops.

Ads are self-hosted.