I have been playing a lot with CSS these days, and then I came across the concepts of using variables inside it. I came to know of two ways to do so, SASS and LESS. I was eager to try both out but it was only possible one at a time. So I chose SASS first, since a couple of friends of mine suggested it to be better, and that SASS compiles into CSS on the server side as opposed to the client side in LESS (using javascript). Also I saw Bootstrap v4 dumping LESS for SASS. So, that made the choice pretty much obvious. In this post, I will cover the very basics of SASS, not dwelling into any code since most people are not using a pre-processor for CSS, so a need for its use needs to be understood first.
Syntactically Awesome Stylesheets (sounds cool, no?) is a CSS pre-processor, that is, it compiles into CSS. It is a scripting language which can contain variables, functions, conditions, loops etc and finally all of it gets compiled in the form of plain old CSS! For the people curious to know about its origins, it is written in Ruby. Though you do not even need to know how to write a “Hello World” program in Ruby to use SASS. Also libsass is preferred over ruby sass these days since it is a lot better and faster choice. Though usually plugins are used to process sass into css, it is worthwhile to know the differences and its evolution.
SASS files have the extension .scss and these files are passed through a pre-processor which converts all of it into a .css file. It is to be noted that a css file is also a valid scss file (unless you are using the older version of SASS, which used to have files name by the extension .sass and were indentation based rather than looking similar to css). Otherwise, a scss file can contain a mixture of css and sass things.
I personally use Visual Studio for development purposes and to compile SASS, I have the Web Essentials extension installed which automatically converts my files for me every time I hit the save button. If you have Visual Studio 2015 installed, the extension has been split into multiple parts and you need to install the Web compiler extension for this. For people not using VS, you can
The benefits of using SASS are:
In short, SASS allows you to use variables, inherit previously used styles in another style, use parameterized functions, loops, conditions, provide nested rules and a lot more, and this all happens using CSS! And you can get a lot more done by writing lesser lines and it will be more readable than your plain old CSS.
If you’re interested in knowing more, I can make a short tutorial for the same in my next post. Do let me know in comments.
I recently switched completely to the Brave browser and have set ad blocking to aggressive…
I was preparing a slide deck for a hackathon and decided to put in a…
I have been using npx a lot lately, especially whenever I want to use a…
Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…
While working on a project, I wanted to do an integrity check of a file…
Popovers have been a problem that was typically solved by using a third-party solution. But…