What is Sass and it’s Applications?
Sass or Syntactically Awesome Stylesheets is a scripting language interpreted into CSS. After the initial release, Sass was extended to SassScript, a basic scripting language that could be used for Sass files. There are two syntaxes in the language, with the original one, Indented Syntax with features similar to Haml, and the later one being SCSS using block formatting similar to CSS. The language uses braces for denoting code blocks and semicolons for separating lines within blocks.
Why Sass is Used?
Sass is especially preferred because it makes it easier, faster and more flexible to author stylesheets. A big reason for using Sass is that the transition from CSS is quite simple. There is no need to make any alterations to the old files. All you have to do is rename the files from .CSS to .SCSS and add a compiler. Sass provides better cross-browser support, which is quite beneficial when you want to use all the latest CSS3 properties. Essentially, it allows you to treat the stylesheets as part of the code base.
Advantages of Using Sass
There are three main properties to Sass that make it an advantage over other options.
1. Nesting – You can write the selectors in the nested format, which eliminates the need to repeat yourself. It is easier to change top sections of selectors and the CSS code is more concise and DRY. Nesting helps make modifier class and selectors elegant and allows you to reference self.
2. Variables – Sass allows you to define variables which could then be used later. The advantage of this feature is that it helps in minimizing copy-pasting of variables such as strings, sizes and colors. Besides, Sass also supports simple operations on variables including string and math operations, and color functions. It is also possible to execute basic level of programming.
3. Mixins – These are functions that could be defined and used across the system. It is possible to use them in separate selectors and passed in arguments. Mixins can be used in two unique forms – a) when it is required to share a function across the website in various contexts, b) when it is required to define “private” functions for better managing CSS and different responsibilities. They can be quite useful when cross-browser support is required.
Sass is officially open-source and it has been coded in Ruby. It has other implementations as well, including libSass in C and PHP.