Yogesh Chauhan's Blog

for @each loop in SCSS

in SCSS on July 19, 2021

For each loop is similar to a for loop in SassScript.

To write a for each loop, you need to use @each rule.

Using @each rule you can go through each element from a list and evaluate a particular style.


@each $var in $list {

Each time the for each loop go through the element and executes a code, it creates a new selector as per the rule.


$widths: 10px, 50px;

@each $width in $widths {
  .img-#{$width} {
    width: $size;

The code above compiled to this CSS:

.img-10px {
  width: 10px;

.img-50px {
  width: 50px;

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
What’s a Web Storage API in JavaScript?JavaScript4 different ways to create JavaScript ObjectsJavaScriptAND, OR and NOT boolean operators in Envision BasicEnvision BasicHow can one check to see if a remote file exists using PHP?PHPHow to set opacity or transparency using CSS?CSSHow does Next.js load pages faster?NextJSHow to obfuscate JavaScript code to hide it from View Source?JavaScriptKeyValuePipe in Angular 9AngularCSS Attribute SelectorsCSSHow to swap images on hover using CSS?CSSHow to send and receive query strings via links in Angular 9?AngularHow to add and remove list items using JavaScript?JavaScript