Why Do We Use SASS Instead Of CSS?

Why Do We Use SASS Instead Of CSS?

What is SASS? A syntactically awesome stylesheet is a CSS preprocessor that lets you use variables, mathematical operations, mixins, loops, functions, imports, and many other exciting functionalities that can make writing CSS much more powerful.
SASS is one of the most widely used CSS preprocessors. CSS preprocessors can extend the basic CSS features by providing you with a set of powerful functionalities that will raise your productivity in less time. SASS is an augmentation of CSS that is utilized to add power and style to the fundamental language. It is also for depicting the introduction of a report written in a language such as HTML.

SASS BENEFITS

  • It’s CSS syntax friendly: If you know CSS, then you also know SASS. SASS comes with two different syntaxes: SASS itself and then SCSS, which is the most used one. SCSS syntax is CSS compatible, so you have to rename your .css file to .scss, and wow! Your first SCSS file has been created, just like that.
*/###### SASS Example ########*/
$font-stack:    Helvetica, sans-serif
$primary-color: #333

body
  font: 100% $font-stack
  color: $primary-color
*/###### SCSS Example ########*/
$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}
  • It offers variable for whatever you want: One of the great benefits of using a CSS preprocessor is that like SASS. It can use variables. A variable allows you to store a value or a set of values, and to reuse these variables throughout your SASS files as many times you want and wherever you want. It is easy, powerful, and useful.
  • It uses the nested syntax: Another fantastic benefit of CSS preprocessors is their improved syntax. SASS allows you to use a nested language, which is a code, that is contained within another piece of code that performs a broader function. Nesting also allows a more transparent way of targeting elements.

Benefits of nesting:

More natural syntax and more comfortable to read in most cases

Prevents the need to rewrite selectors multiple times

Better code organization and structure thanks to its visual hierarchy, which brings us more maintainable code.

  • It includes Mixins: Mixins are like functions in other programming languages. They return a value or set of benefits, and it can take parameters, including default values. Note that SASS also has function, so do not get confused between a mixin with a function.
  • You can divide and conquer: SASS has the @import rule. @import allows you to modularize your code, making it easier to be maintained by importing smaller SASS files. The difference between this and the CSS @import rule is that all imported SCSS files will be merged into a single CSS file, therefore, in the end, only a single HTTP call will be requested because you will be serving a separate CSS file to the webserver.
  • It has a large community and is well documented: Another advantage of using SASS is the tremendous amount of documentation available online. From tutorials to books, SASS has all you need to learn and become an expert. One of the best starting points is the official SASS Documentation page, where you will find excellent documentation full of practical examples.
  • If you know SASS, you can customize bootstrap 4: If you are familiar with Bootstrap, knowing SASS will give you the ability to change this web framework by merely customizing the SASS code. Sounds impressive, right? And also the good thing is that it’s super easy to do and you only have to change the value of some of the variables.

SASS DRAWBACK

  • Debugging is harder: SASS has a compilation step which means that CSS line numbers are irrelevant when trying to debug code. But Debug is much harder than programming which can be a considerable drawback.
  • Compilation slows down development: Compilation times can also be prolonged, even when you are using the best tools on the fastest computer. You know that feeling you get when you refresh and don’t see any changes—yeah right that.
  • Tooling and developer convenience: CSS preprocessors require extra tooling, and Code authors shouldn’t be forced to use a particular editor just to be able to use the tool. That’s the tail wagging the dog. Also, extra stuff adds complexity. This needs to be understood, upgraded and maintained – all of which increases cost and a higher risk of problems.
  • Capability and understanding: While CSS pre-processors and the workflows around them have become widespread, there is still a knowledge gap. Particularly, when it comes to an understanding of the trade-offs. Here’s a big difference between understanding a tool, and using it effectively without introducing other problems.
  • They can produce substantial CSS files: Source files may be small, but the generated CSS could be huge, which is what counter need to be aware that in using a CSS pre-processor, we are losing some control.

CONCLUSION

In this article, you can see lists of benefits and drawbacks of SASS and why it is better than CSS. Becoming a SASS guru may take a bit of your time; all you need to do is look into the Bootstrap SASS files and see how SASS could turn into a complicated thing. But learning the basics and setting it up for your project won’t take you long for sure. Also, the maintenance and readability of CSS get harder as the project gets bigger. Dealing with thousands of lines of CSS rule wastes developer’s time and also raises the cost of the project. So SASS, a preprocessor, helps us deal with these problems.

Share and Enjoy !

0Shares
0 0

Leave a Reply