math.compatible($number1, $number2) returns whether the two numbers have compatible units. If it returns true, they can safely be added, subtracted, or compared. Otherwise those operations will error. Load it with @use "sass:math" (Dart Sass 1.23+ for modules).
Official docs: the global helper stayed comparable, but the module renamed it to compatible to say what it checks. Prefer math.compatible; global built-ins are deprecated in modern Dart Sass.
Boolean only — no conversion.
This function does not change units. It answers yes/no so your mixins can branch before +, -, comparisons, or math.clamp.
Syntax
Syntax
SCSS
@use "sass:math";
math.compatible($number1, $number2); //=> boolean
math.compatible(2px, 1px); // true
math.compatible(100px, 3em); // false
math.compatible(10cm, 3mm); // true
// Global name (legacy / deprecated in modern Dart Sass)
comparable(2px, 1px); // true
// Module API — prefer math.compatible after @use "sass:math"
Pattern: inspect tokens → branch with @if → only then add or compare. Inspect units with math.unit and math.is-unitless.
Reference
When Units Match
Common pairs and their verified results:
Call
Result
math.compatible(2px, 1px)
true
math.compatible(10cm, 3mm)
true (compatible absolutes)
math.compatible(100px, 3em)
false
math.compatible(10, 3)
true (both unitless)
math.compatible(10, 3px)
true (unitless with length)
math.compatible(10%, 3%)
true
What “compatible” unlocks.
When this returns true, Sass can add, subtract, and compare the values. Absolute lengths like cm/mm may convert during those operations.
Module name is compatible; global alias is comparable.
Prefer math.compatible over deprecated global comparable().
One line: before adding or comparing uncertain Sass numbers, call math.compatible($a, $b).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Call math.compatible($a, $b)
3. true → safe to add / subtract / compare
4. false → normalize units or pick a fallback
5. Prefer math.compatible over global comparable()
Frequently Asked Questions
math.compatible($number1, $number2) returns true when the two numbers have compatible units, and false otherwise. Unitless values are compatible with each other and with lengths. If it returns true, you can safely add, subtract, or compare them.
Add @use "sass:math"; then call math.compatible($a, $b). Example: math.compatible(2px, 1px) is true; math.compatible(100px, 3em) is false.
Official docs note that the global function is comparable($number1, $number2). When it moved into sass:math, the module name became compatible to describe the check more clearly. Prefer math.compatible() in new code.
No. It only answers yes or no. If the answer is true, other operations (like $a + $b or math.clamp) can convert compatible absolute units as needed.
Use it in mixins, maps, or theme helpers before you add or compare values that might mix unit families (for example px vs em). Guard with @if math.compatible(...) to avoid compile errors.
Built-in modules with @use need Dart Sass (about 1.23+). Older setups can still call the global comparable() name, but modern Dart Sass deprecates global built-ins. Prefer math.compatible().