CSS3 preprocessors are languages for the purpose of helping
in creating styles compatible with all browsers and with several
resources to help us, especially when we have huge CSS’s.
The most important thing is to recognize the syntax, and lucky for us all these preprocessors use a language similar to each other.
Sass and LESS
Both use standard CSS syntax and this makes it very easy.
Sass uses the extension .scss
and the LESS uses .less
.
The code below works on Sass or LESS.
/* style.scss or style.less */
h1 {
color: #0565CC;
}
It is important to note that Sass also has an older syntax, which omits semicolons and keys. Although this one is still out there, it’s old and can’t use it beyond this example.
The syntax uses the file extension .sass
and looks like this:
/* style.sass */
h1
color: #0565CC
Stylus
The syntax for Stylus is much more detailed. Using the file extension .style
, Stylus accepts the standard CSS syntax, but also accepts some other variations,
colon and semicolon are all optional. For example:
/* style.styl */
h1 {
color: #0982C1;
}
/* omitor colchetes */
h1
color: #0982C1;
/* omitir dois pontos e virgular */
h1
color #0982C1
Using different variations of the same style is also valid, so the following example will compile without errors:
h1 {
color #0982c1
}
h2
font-size: 1.2em
Each of the above files will compile to the same CSS.
You can use your imagination to see how useful it can be for your project.
With these techniques you will not need to write the same color or pattern several times, using variables you can greatly decrease and simplify your code.
I see no advantage in using an X technique compared to Y, it goes of the programmer’s taste.
But one thing without a shadow of a doubt is the gain over code organization, how you assemble your CSS and work on it.
+1
- There is a another question which refers only to Sass and Less, I think Stylus is an important comparison element.– Sergio
Before they voted to close because it was based on opinions. The question is quite objective, it asks an analytic comparison between the 3 preprocessors, does not ask which of them is the best.
– Omni
I don’t think it is based on opinions, but I find it very broad (several questions in one).
– Pablo Almeida
if you ask ten people what your favorite processor pre, you will get eleven different answers.
– Cleiton