Skip to content
Related Articles

Related Articles

Improve Article
CSS Preprocessor | SASS
  • Difficulty Level : Medium
  • Last Updated : 28 Jan, 2019

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:

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>
        <meta charset="utf-8"/>
        <meta name="viewport" content=
            "width=device-width, initial-scale=1">
        <link rel="stylesheet" href="style.css">
        <div id="d1">Welcome to GeeksforGeeks.
                <li>CS subjects</li>
  • 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


  • 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.


    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:

My Personal Notes arrow_drop_up
Recommended Articles
Page :