Sass supports a full set of operators for arithmetic, comparison, logic, and string manipulation. This lesson covers each category with practical examples, including why math.div() replaced the plain division operator.
What Operators Does Sass Support?
Sass provides arithmetic operators (+, -, *, %), comparison operators (==, !=, <, >, <=, >=), logical operators (and, or, not), and string concatenation through interpolation or the + operator on strings.
Division uses math.div() instead of /, since / is reserved for plain CSS shorthand like font: 16px/1.5.
Sass Operators Cheatsheet
The operators you'll use across variables, control rules, and functions.
Operator
Example
Result
+
4px + 6px
10px
-
10px - 4px
6px
*
2 * 8px
16px
%
7 % 2
1
math.div()
math.div(100%, 4)
25%
== / !=
$a == $b
true / false
<><=>=
$width > 768px
true / false
and / or / not
$dark and $large
Combined boolean
+ on strings
"Hello " + "World"
"Hello World"
Arithmetic Operators
Arithmetic operators work directly on numbers, and Sass respects CSS units during the calculation, adding two px values produces a px result, multiplying a number by a unitless number keeps the original unit.
Plain CSS already uses / for shorthand properties like font: 16px/1.5 and border-radius: 4px / 8px. Because of this ambiguity, Dart Sass deprecated using / for actual division and introduced math.div() as the unambiguous replacement.
Comparison operators return true or false and are most useful inside @if statements or when building conditional function logic. Logical operators combine multiple boolean checks into one expression.
Using / for division and getting unexpected results or deprecation warnings; use math.div() instead.
Comparing values of incompatible types (like a string and a number) and being surprised the result is always false rather than an error.
Forgetting operator precedence, multiplication and division bind tighter than addition and subtraction, just like in most programming languages.
Trying to use && or || instead of Sass's actual keyword-based and/or logical operators.
Key Takeaways
Sass supports arithmetic, comparison, logical, and string operators.
Arithmetic respects CSS units and raises an error for incompatible unit combinations.
math.div() replaced / for numeric division to avoid ambiguity with CSS shorthand syntax.
Logical operators use the keywords and, or, and not, not symbolic operators.
Pro Tip
Whenever you need to divide two numbers, reach for math.div() immediately instead of /, this avoids deprecation warnings today and future compile errors once / is fully repurposed for CSS-only syntax.
You now understand Sass's operators for arithmetic, comparison, and logic. Next, dive into working with colors, one of the most common use cases for Sass functions.