Advantages of using SASS (Preprocessor) compare to use normal CSS
SASS stands for Syntactically Awesome Style Sheets. There are many advantages of Using SASS in your project compare to normal CSS.
The main advantage is Code reusability and writing less code. It is easy to maintain and scale the CSS.
We can create variable for color, font, size etc and use it anywhere we want.
for example:
$primary-color: #e1e1e2;
$font-stack: 'Roboto', sans-serif;
button {
background-color: $primary-color;
font-family: $font-stack;
}
For better code organization we can use Nesting
for example:
ul {
list-style: none;
}
li {
display: inline-block;
}
For code reusability we can use Mixin
for example:
@mixin box($width, $height) {
width: $width;
height: $height;
display: flex;
justify-content: center;
align-items: center;
}
.card {
@include box(300px, 200px);
}
We can use extend for inheritance.
for example:
.message {
padding: 10px;
border: 1px solid #ccc;
}
.success {
@extend .message;
border-color: green;
}
For modularity we can use partials and imports
for example:
@use 'variables';
@use 'buttons';
@use 'layout';
We can use loop as well as mathematical operations with Sass as well. It is cross browser compatible as well. Can be easily integrated with any build tools.
In short Sass turns CSS into a maintainable, modular, and programmable language which is ideal for large-scale front-end projects.
Happy Reading!!!
Excellent explanation with examples