I'll share what I know and some sources on the subject.
What do they do exactly?
LESS
, SASS
and SCSS
are extensions of CSS
, that is, in a very simple way, they add functionality to CSS .
Taking the Web development context, we can think of how TypeScript
is for Javascript
, adds new features, without breaking the compatibility, that is,
at the end the code is compiled, or converted to a standard version. So do these CSS preprocessors.
A more functional example helps to understand.
Scenario 1, contents repeated throughout CSS. It is common for the company to provide the color palette and colors to be set to this standard.
Then the same RGB appears several times in CSS. Or the name of the sources, and so on. When you need to find the colors, you have to resort to searching, and when you want to change for example, you have to go out changing the whole code. If you had a basic programming language functionality in CSS, which are variables, this would be easily solved.
Example:
.estilo1 {
background-color: #fafafa; /* uma cor padrão */
font: Helvetica, sans-serif
}
.estilo3 {
color: #fafafa
}
.estilo4 {
background-color: #fafafa; /* novamente, de uma maneira que foi inevitável não duplicar...*/
font: Helvetica, sans-serif
}
Now it would not be easier to see and change if it were something like this:
$cor-padrao: #fafafa
$font-padrao: Helvetica, sans-serif;
.estilo1 {
background-color: $cor-padrao;
font: $font-padrao
}
.estilo3 {
color: $cor-padrao
}
.estilo4 {
background-color: $cor-padrao;
font: $font-padrao;
}
This second code, after being processed, will be generated equal to the first one, not causing incompatibility with browsers.
This is a simple example, but you can see how easy it can be to do certain things, make the code clear, and also simpler to maintain, you could change the default color only in the variable and all CSS code would already be reflecting the change.
Another good example is the Mixins feature, which allows you to reuse a portion of CSS as if it were a function. Here's an example:
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
.box { @include border-radius(10px); }
Source: link
In which cases would it be useful to use them instead of conventional CSS?
Well, I could tell everyone. Whenever you have an extension, as you master begins to use more, then begin to realize more options of where it can be useful.
It is possible to write a 100% code in the preprocessor, and, as you master the features, you are implementing what makes the learning curve smooth.
Would not it hurt page performance instead of using normal CSS since it would be an overprocess or cost x benefit worth?
As the code can be compiled and delivered as a normal CSS, there is no incompatibility the cost would be to wait a few seconds (not enough, but if you charge ...) just in time to assemble the package to publish, I do not think it's great hindrance
Some IDEs also allow you to compile the code while it is being saved, which makes the process even simpler and more transparent.
Here is a link to another very simple explanation of the features: tableless.com .br / sass-a-other-method-of-writing-css