CSS Preprocessor | SASS
SASS is the abbreviation of Syntactically Awesome Style Sheets. It is a CSS pre-processor with syntax advancements. The style sheets in the advanced syntax are processed by the program and compiled into regular CSS style sheets, which can be used in the website. It is a CSS extension that allows to use features like variables, nesting, imports, mixins, inheritance, etc, all in a CSS-compatible syntax.
Note: The link describes the installation process of SASS. Ref: https://sass-lang.com/install
There are two types of syntax available for SASS:
- SCSS(Sassy CSS): The files using this syntax use .scss extension.
- Indented syntax (referred to as just “sass”): older syntax, Files using this syntax use .sass extension.
Note: This example use .scss extension.
Working Steps:
- Write the SCSS code.
- Compile the SCSS code into CSS code using the command sass input.scss output.css. The first filename (input.scss) is the scss file that is to be compiled and the second file name (output.css) is the processed CSS file, to be included/attached in the html document.
- Include the compiled CSS file in the html file.
Now see how to make effective use of the important features of SCSS like variables, nesting, mixins and operators.
- The main HTML file is named index.html
- SCSS file is styling.scss and the CSS file is style.css
- Command to compile the SCSS file: sass styling.scss style.css
Example: File name index.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>SASS</title> <meta name="viewport" content= "width=device-width, initial-scale=1"> <link rel="stylesheet" href="style.css"> </head> <body> <div id="d1">Welcome to GeeksforGeeks. <ul> <li>Algo</li> <li>DS</li> <li>Languages</li> <li>Interviews</li> <li>CS subjects</li> </ul> </div> </body> </html> |
- Variables: Variables can be used to store CSS value that may be reused. To declare a variable in SASS, ‘$’ character is used. Example: $v_name
After compiling the CSS code save it file by style.css

- Nesting: SASS allows CSS rules to be nested within each other, which follows the same visual hierarchy of HTML. For Example: CSS property can be used to the <li> tag nested inside the div tag.
After compiling the CSS code save it file by style.css

Output:

- Mixins: Mixins helps to make a set of CSS properties reusable i.e. it save one code and use it again and again. It can be included in other CSS rules by using @include directive.
Example:

After compiling the CSS code becomes:

The output of web page:

Example: Mixins can also take variables as arguments. The values are passed while including them in the CSS rules.

The compiled CSS code:

Final Output:

Recommended Posts:
- How to access an object having spaces in the object's key using JavaScript ?
- How to move an element to left, right, up and down using arrow keys ?
- How to check a checkbox with jQuery?
- What is the Efficient way to insert a number into a sorted array of numbers?
- How to merge the duplicate value in multidimensional array in PHP ?
- How to Show and Hide div elements using Checkboxes ?
- How to get the first key name of a JavaScript object ?
- How to animate div width and height on mouse hover using jQuery ?
- How to make horizontal scrollable in a bootstrap row?
- What is the difference between offsetHeight and clientHeight ?
- How to disable scroll to change number in <input type="number"> field using JavaScript/jQuery?
- How to add sleep/wait function before continuing in JavaScript?
- PHP Full Form
- Laravel | Installation and Configuration
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



