Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor that provides a level one experience for CSS. Sass has special features that make it easy for users to explore and edit CSS code. Although Sass was created almost 15 years ago, it is still popular and considered the best way to improve the CSS process on the job.
First of all you need to install Sass on your system. Sass is not installed by specific software, but you can easily install Sass by running the following command using Terminal:
npm install -g sassThis command will install Sass on the system with the required functions of your document.
Now create a sass file to write your sass code. Sass file names use .scss or .sass as the extension.
.scss is Sass's standard syntax, which looks like CSS and is translated using Sass. On the other hand, .sass is Simple Syntax, which does not look like CSS and does not translate to Sass. Whichever one you use doesn't make a big difference in the case of how easy it is for you and recommend.
To get the most powerful features of Sass, you need to learn Sass syntax. Some basic things to know about Sass syntax:
Variables are declared with the $ sign. For example, $color: red;. Almost everything code related can be easily written in Sass using nested selectors and properties. For example,
.container { color: blue; p { font-size: 14px; } }
Mixin is a natural feature of Sass, which allows you to reuse styles. It's a block of code that you can reuse and apply in multiple places. For example,
@mixin center { display: flex; justify-content: center; align-items: center; } .container { @include center; }While these steps illustrate some of the syntax features, Sass has more experience and concepts. Hence, most Sass documentation and tutorials are published on the Internet, which can help you with the detailed content and usage of Sass.
After writing the Sass code, you need to compile it so that the Sass code is transpiled into a normal CSS file. For this you can use command line or any sass compiler.
sass input.scss output.css
Here, input.scss is the name of your css file and output.css is the name of the output file.
There are many methods and tools for compiling Sass, and even IDEs and text editors can provide Sass compilation. You can compile Sass with any tool or method of your choice.
This way, you can start learning Sass. Always try to learn basic Sass syntax and concepts at the beginning and move on to the later advanced topics.