In this tutorial, we will be learning how to identify and resolve compilation errors in SASS/SCSS. SASS (Syntactically Awesome Stylesheets) is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). SCSS (Sassy CSS) is a super set syntax of CSS, it means every valid CSS is a valid SCSS.
Goals of this tutorial:
What you will learn:
Prerequisites:
Errors in SASS/SCSS can come in many forms like syntax errors, undefined variables, invalid CSS, etc. These errors stop the compiler from executing the code.
Compilation errors are typically identified by error messages that appear during the compilation process. These messages will tell you where the error occurred and give you hints on what might have gone wrong.
Resolving these errors usually involves correcting the syntax, defining any undefined variables, or fixing invalid CSS.
// incorrect syntax
$str: "Hello, World
p {
content: $str;
}
The above code will result in a syntax error because the string variable $str
is not properly closed. Here is the correct code:
// correct syntax
$str: "Hello, World";
p {
content: $str;
}
// undefined variable
p {
color: $main-color;
}
The above code will result in an error because the variable $main-color
is not defined. Here is the correct code:
// defined variable
$main-color: #333;
p {
color: $main-color;
}
In this tutorial, we learned about common compilation errors in SASS/SCSS, how to identify them using error messages, and how to resolve them. As a next step, you could learn more about SASS/SCSS features like mixins, inheritance, and operators.
// Exercise 1
$font-size = 16px;
p {
font-size: $font-size;
}
Solution: The variable $font-size
is not defined correctly. In SASS/SCSS, variables are defined using :
and not =
.
Corrected code:
$font-size: 16px;
p {
font-size: $font-size;
}
// Exercise 2
$color: #333
p {
color: $color
}
Solution: The lines are not properly closed with ;
.
Corrected code:
$color: #333;
p {
color: $color;
}
Keep practicing and try to write more complex SCSS code to understand the common errors and their solutions.