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 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #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
How to set up the local environment and workspace for Angular development?AngularCan We Use For Loop to Loop Through Associative Arrays in PHP?PHPHow to add a new role in WordPress?WordPressHow services and dependency injection work in Angular?AngularDoes :is() pseudo selector hint at CSS preprocessing in the future?CSSINTERSECT and EXCEPT in PostgresPostgresHow to progressively load images and add a blurry placeholder?CSSThe Lending Club Analysis using Logistic Regression and Random Forest in RStudioMiscellaneousWordPress: How to print ACF repeater field values?WordPressHow to change the Login Logo in WordPress?WordPressHow to remove a specific item from an array in JavaScript?JavaScriptHow to read Standard Input in Swift?Swift