![]() |
VOOZH | about |
SASS (Syntactically Awesome Style Sheets) is a pre-processor for CSS that provides various features such as nesting and mixins. SASS compiles to regular CSS and that CSS is used in your project and finally by the browser to style the web page.
Let's understand how Sass works:
Let's understand why developers prefer Sass:
The following steps provides the way of installing Sass using npm:
Download and install Node.js from the official site. The installer will also install the npm command. To verify the presence of npm use the npm command along with the version flag as shown below.
npm -versionInstall the SASS package globally so that you can use it in all your projects without manually installing it.
npm install -g sassUse the SASS command to watch or generate the CSS code from the SASS code. The command also generates a file_name.css.map file which is a source map used by browsers for generated CSS code from the SCSS code.
sass file_name.scss any_name.cssAlternatively you can use the watch option to generate the CSS code every time any changes made to the SASS file.
sass --watch file_name.scss any_name.cssThe below example shows a SASS file having both the basic CSS syntax and additional features of SASS. Create a HTML file named as index.html and a SASS file name as input.scss. Paste the following code into these file then run the watch SASS command explained above to create the CSS file but if you want to change the name then do not forget to change the name in the link tag in the HTML file.
Example: The below code will show how you can use SASS with CSS.
Output: