Yogesh Chauhan's Blog

How to define variables in SCSS (Sass)?

in SCSS on May 7, 2021

Sass or SCSS variables are similar to PHP variables in one way. Just assign a value to a variable name that starts with a dollar sign ($).

Just like this:


$base-color: #c6538c;

Sass (SCSS) Variables are really helpful in reducing repetition and even complex math calculation.

Sass doesn’t differentiate between hyphens and underscores when it comes to variable names. So, $font-size and $font_size both are like calling the same variable.

The SCSS code above for ‘alert‘ class compiles into this CSS:


.alert {
  border: 1px solid rgba(255, 76, 76, 0.88);
  color: #ff4c4c;
}


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
How to Check If a Variable is an Integer, a Float, a Number, NaN, an Infinite or a Numeric in PHP?PHP@forward rule in SCSS (Sass)SCSSHow to hide and show menu on scroll using JavaScript and CSS?CSSHow to add multiple Columns in CSS like Bootstrap?CSSFull and Partial CUBE in Postgres with ExamplesPostgresWhat Does Host-Based Intrusion Detection System (HIDS) Mean and What Are Some Advantages Over NIDS?MiscellaneousHow to define visibility for a property in PHP?PHPAll different methods for accessing elements in the DOM using JavaScriptJavaScriptHow to create a sidebar using pure CSS?CSSHow to convert a function component into a class in React?ReactSolution for Xcode 11 Command PhaseScriptExecution failed with a nonzero exit code errorMiscellaneousWordPress: How to loop through a repeater field in ACF?WordPress