Sass — Debugging
@debug
$color: #3498db;
.button {
@debug "Button color: #{$color}";
background: $color;
}
@warn
@mixin old-syntax($color) {
@warn "This mixin is deprecated. Use new-button instead.";
background: $color;
}
.button {
@include old-syntax(blue);
}
@error
@mixin grid($cols) {
@if $cols < 1 or $cols > 12 {
@error "Columns must be between 1 and 12";
}
width: math.percentage(1 / $cols);
}
Inspecting output
# See compiled CSS
sass input.scss
# Watch with verbose output
sass --watch input.scss:output.css --style expanded
Common errors
Undefined variable
// Error: Undefined variable
.button {
background: $primary;
}
// Fix: define the variable
$primary: #3498db;
Invalid nesting
// Error: Properties can only be nested
.button {
.color { // WRONG - .color is a selector
blue;
}
}
// Fix
.button {
.color {
color: blue; // Property name needed
}
}
Circular reference
// Error: circular reference
$a: $b;
$b: $a;
// Fix: use one variable
$a: #3498db;
$b: $a;
Source maps
sass --source-map input.scss output.css
Source maps help debug in browser dev tools:
- Open browser DevTools
- Find the .scss file in Sources tab
- Set breakpoints in Sass code
- Inspect computed styles
Mini Practice
- Use @debug to inspect variable values
- Add @warn for deprecated features
- Test @error with invalid inputs
- Generate source maps and inspect in browser
Up Next
Continue with Performance — optimizing Sass for speed.
Related Topics
Frequently Asked Questions about Debugging
What is Debugging in Sass?
Debugging is a fundamental concept in Sass. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Debugging?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Debugging.
Why is Debugging important in Sass?
Debugging is essential for Sass development. Understanding this concept will help you write better code and solve real-world problems more effectively.