Yogesh Chauhan's Blog

Configuring Modules with @forward rule in SCSS (Sass)

in SCSS on June 3, 2021

Configuring modules with @forward rule is similar to configuring modules with @use rule.

The difference is that you can use the !default flag in it’s configuration while configuring with @forward module.

That is very handy since you can use the other modules members with no values can have default values and if they have values then you can use that value.

For e.g. let’s say you have a _fonts.scss file with the following styles:

// _fonts.scss
$black: #000 !default;

.arial {
  color: $black;

Let’s forward that stylesheet into another one.

// _fonts_adjusted.scss
@forward 'fonts' with (
  $black: #222 !default,

Finally, let’s use it in the main stylesheet.

// main.scss
@use 'fonts_adjusted' with ($black: #333);

This is how it’ll compile into CSS at the end:

// main.scss
.arial {
  color: #333;

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
List of all Pseudo Elements in CSSCSSWordPress: How to get ACF field values from another post?WordPressHow to get the first element with a class name xyz using JavaScript?JavaScriptHow to Draw a Text Image using JavaScript?JavaScriptSlider animation using CSS transform propertyCSSSorting Arrays in JavaScriptJavaScript12 URLSearchParams methods in JavaScriptJavaScriptHow to use images instead of HTML radio buttons using CSS?CSSWhat does it mean by Continuous Integration, Continuous Delivery and Continuous Deployment?MiscellaneousHere’s what we can do with PHP date() functionPHPHow JavaScript classes allows us to do less typing (syntactic sugar)?JavaScriptHow to apply style only to first child and/or only to children other than the first child?CSS