Sass numeric operators perform math on numbers: add, subtract, multiply, and modulo. Prefer math.div() for division. This page covers units, unary +/-, complex units, percentages, and five compiled examples.
01
Operators
+-*%
02
Division
math.div()
03
Units
Auto-convert
04
Unary
+ / -
05
Complex
px*px, rates
06
Practice
5 examples
Concept
What Are Numeric Operators?
Official docs: Sass supports the standard set of mathematical operators for numbers. They automatically convert between compatible units.
Math runs when Sass compiles—not in the browser.
Results are numbers (sometimes with complex units).
Unitless values can mix with any unit for these operators.
Incompatible units fail for +, -, and %.
Use math.div() instead of deprecated / division.
💡
Beginner tip
Think of a calculator for CSS tokens: $base * 2 or $pad + 4px. Keep units on your numbers so Sass can check your math.
Official docs: when two numbers are multiplied, their units multiply. When one number is divided by another, the result takes numerator units from the first and denominator units from the second.
Expression
Idea
Inspected result
4px * 6px
Square pixels
24px*px
math.div(5px, 2s)
Pixels per second
2.5px/s
1in + 6px
Compatible lengths
1.0625in (or 102px)
💡
Unit-clean math
If the unit looks wrong, check the formula. Avoid #{$number}px—that builds a string, not a number. Prefer $number * 1px or keep the unit on the variable from the start.
Percentages vs decimals
Official docs: percentages are not interchangeable with decimals. 50% has a % unit; 0.5 does not.
math.div($percentage, 100%) → decimal
$decimal * 100% or math.percentage($decimal) → percent
Cheat Sheet
⚡ Quick Reference
Goal
Code
Add / subtract
$a + $b / $a - $b
Multiply / modulo
$a * $b / $a % $b
Divide
math.div($a, $b)
Negate
-$value or -($a + $b)
Percent ↔ decimal
$d * 100% / math.div($p, 100%)
Attach a unit
$n * 1px (not #{$n}px)
Slash separator
list.slash($a, $b)
Hands-On
Examples Gallery
Each example uses numeric operators at compile time. Open View Compiled CSS for verified output (values shown with meta.inspect where helpful).
One base size drives several properties. Multiplication, subtraction, and math.div all resolve before CSS is written.
Applications
🚀 Real-World Use Cases
Spacing scales — derive padding and gaps from a base token.
Type scales — multiply or divide to build modular sizes.
Duration math — convert ratios like pixels-per-second into times.
Percent helpers — convert opacity decimals to percentages safely.
Grid math — compute column widths and gutters at compile time.
🧠 How Compilation Works
1
Write an expression
Use +, -, *, %, or math.div().
Source
2
Resolve units
Convert, multiply, cancel, or error on incompatible units.
Compile
3
Emit a CSS value
Write finished lengths, times, or calc-style complex units.
Emit
4
✓
CSS ships
Browsers only see values like width: 160px.
Watch Out
⚠️ Common Pitfalls
Deprecated / division — use math.div().
Incompatible + / - — 100px + 10s fails.
Minus ambiguity — space carefully in lists; prefer parentheses.
#{$n}px — creates a string, not a number.
Percent ≠ decimal — convert explicitly with unit math.
Pro Tips
💡 Best Practices
✅ Do
Use math.div() for all new division
Keep units on tokens from the start
Space both sides of binary -
Use unit ratios for duration ↔ distance math
Convert percentages with * 100% / math.div(..., 100%)
❌ Don’t
Rely on slash / as division
Interpolate units with #{$n}px
Add length to time or other incompatible families
Treat 50% as 0.5 without converting
Expect browsers to evaluate Sass math
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass numeric operators
Do compile-time math with units, and divide with math.div().
5
Core concepts
📝01
Operators
+ − × %
Call
🔢02
Division
math.div()
Modern
🔗03
Units
convert & cancel
Rule
➖04
Unary
+value / -value
Signs
✓05
Clean
keep units on numbers
Habit
❓ Frequently Asked Questions
They are the standard math operators for numbers: + (add), - (subtract), * (multiply), and % (modulo). They convert between compatible units at compile time.
Use math.div($a, $b) from the sass:math module (Dart Sass 1.33+). Using / as a division operator is deprecated because CSS also uses / as a separator.
Yes. Official docs: unitless numbers can be used with numbers of any unit. Example: 100px + 50 equals 150px.
Addition, subtraction, and modulo with incompatible units (like 100px + 10s) cause a compile error. Multiplication and math.div can produce complex units instead.
No. In Sass, 50% is a number with a % unit, not the same as 0.5. Convert with math.div($percentage, 100%) or $decimal * 100% (or math.percentage()).
Interpolation creates an unquoted string that looks like a number but cannot be used in math. Prefer keeping the unit on the number, or write $number * 1px.
Did you know?
Official Sass docs show a transition duration computed as (120px - 10px) * math.div(1s, 50px) → 2.2s because the px units cancel—real unit math, not string concatenation.
Sass numeric operators give you compile-time arithmetic with real unit rules. Use +, -, *, and % confidently, divide with math.div(), and keep math unit-clean so Sass can catch mistakes early.