Sass stands for Syntactically Awesome Stylesheets
Sass is a CSS preprocessor which makes your work simple by facilitating you with variables, mixins, inheritance and ton of cool features that help you to write codes in a much less time. It can be pretty helpful for creating nice & neat code.
Sass consists of two syntax:
Sass is the original syntax, called “The indented Syntax”. This syntax doesn’t require curly braces and semicolon that are a require in CSS. Using newlines and indentation(two white spaces), Sass is able to read and compile as if they were there:
SCSS – “Sassy CSS” is newer syntax that uses block formatting same as CSS. SCSS is uses the curly brackets to identify code blocks and semicolon to separate lines in blocks:
How it Works?
Sass is command line CSS compiler that reads and compiles the codes to clean and structured CSS that you have write in .sass or .scss. For example,
Some Features of Sass
The advantages of using Sass are the drivers behind the usage which is:
- Implementing the DRY(Don’t Repeat Yourself).
- Adding dynamic programming functionality instead of a very static language: CSS
- Code Reusability(Inheritance)
Let’s get familiar with Compass
Compass is an extension of Sass. It has its own compiler so, you use compass watch command instead of sass –watch.
It is a CSS framework that contains large collection of mixins and functions that you will find incredibly useful. This will generate a set of codes in your CSS file with the values you pass as parameters. For example,
Sass provides way to be able to use variables within CSS before it is compiled, allowing for re-usable data. The Sass variables begin with dollar sign($).
This is one of the more useful features of Sass along with the variables. It allows you to target particularly nested HTML components such as navigation:
@import functionality but each time you use
@import in CSS it creates another HTTP requests. In Sass, it avoids to creating additional HTTP requests because files are imported and concatenated on compile rather than browser run-time.
Mixin is a very brilliant feature of Sass and i personally love it. The excellent example of this feature is, when you need to use CSS property that has a vendor prefixes. For example,
box-shadow and many other.
Like many other programming languages, Sass has operator to perform basic math operation in your CSS.
Most of all programming language has this feature called “inheritance”. Using
@extend, you can share CSS properties from one selector to another so it helps keep your Sass very DRY
Sass is very easy to use and understand. I swear that, once you understand the Sass’ methods and syntax, you’ll never want to go back to writing static CSS again.