Sass Numeric Operators

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
+ − × % · math.div

What You’ll Learn

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

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.

📝 Syntax

styles.scss
@use "sass:math";

$a + $b   // add
$a - $b   // subtract
$a * $b   // multiply
$a % $b   // modulo (remainder)

math.div($a, $b)  // divide (preferred)

Operators

OperatorNameWhat it does
+additionAdds the first value to the second
-subtractionSubtracts the second value from the first
*multiplicationMultiplies the values (units multiply too)
%moduloRemainder after division
math.div()divisionDivides the first by the second (Dart Sass 1.33+)

Official samples

ExpressionResult
10s + 15s25s
1in - 10px0.8958333333in
5px * 3px15px*px (square pixels)
1in % 9px0.0625in

🔢 Unitless Numbers

Official docs: unitless numbers can be used with numbers of any unit.

ExpressionResult
100px + 50150px
4s * 1040s

⚠️ Incompatible Units

Official docs: numbers with incompatible units can’t be used with addition, subtraction, or modulo.

styles.scss
// Error: Incompatible units px and s.
@debug 100px + 10s;
  • Length + time fails (px + s).
  • Multiplication / math.div may create complex units instead of failing.
  • Keep addition and subtraction in the same measurement family.

➖ Unary Operators

Official docs: you can write + and - as unary operators that take only one value.

OperatorMeaningExample
+$Returns the value unchanged+(5s + 7s)12s
-$Returns the negative value-(50px + 30px)-80px

Hyphen / minus clarity

Because - can mean subtraction or unary negation, official docs recommend:

  • Spaces on both sides of - when subtracting.
  • A space before - but not after for a negative number.
  • Wrap unary negation in parentheses inside space-separated lists.
styles.scss
@debug 5px - 3px;   // subtraction → 2px
@debug 1 -2 3;      // list: 1, -2, 3

$number: 2;
@debug 1 -$number 3;     // unary then list → -1 3
@debug 1 (-$number) 3;   // safer → 1 -2 3

🔢 Division With math.div()

styles.scss
@use "sass:math";
@use "sass:list";

@debug math.div(15px, 30px);           // 0.5
@debug list.slash(15px, 30px);         // 15px/30px (separator)

⚖️ How Units Work

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.

ExpressionIdeaInspected result
4px * 6pxSquare pixels24px*px
math.div(5px, 2s)Pixels per second2.5px/s
1in + 6pxCompatible lengths1.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

⚡ Quick Reference

GoalCode
Add / subtract$a + $b / $a - $b
Multiply / modulo$a * $b / $a % $b
Dividemath.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 separatorlist.slash($a, $b)

Examples Gallery

Each example uses numeric operators at compile time. Open View Compiled CSS for verified output (values shown with meta.inspect where helpful).

📚 Getting Started

Official +, -, *, and % samples.

Example 1 — Basic Arithmetic

Add, subtract, multiply, and modulo with units.

styles.scss
@use "sass:meta";

.ops {
  --add: #{meta.inspect(10s + 15s)};
  --sub: #{meta.inspect(1in - 10px)};
  --mul: #{meta.inspect(5px * 3px)};
  --mod: #{meta.inspect(1in % 9px)};
}

How It Works

Matches the official docs. Multiplication keeps both units (px*px). Compatible lengths convert during subtraction and modulo.

Example 2 — Unitless & Unary

Mix unitless values, then flip signs with unary operators.

styles.scss
@use "sass:meta";

.ops {
  --ul-add: #{meta.inspect(100px + 50)};
  --ul-mul: #{meta.inspect(4s * 10)};
  --unary-plus: #{meta.inspect(+(5s + 7s))};
  --unary-neg: #{meta.inspect(-(50px + 30px))};
  --unary-flip: #{meta.inspect(-(10px - 15px))};
}

How It Works

Unitless sides adopt the other unit. Unary - negates the whole grouped expression—so -(10px - 15px) becomes 5px.

📈 Practical Patterns

Division, unit ratios, and everyday layout math.

Example 3 — math.div() & Percentages

Divide safely and convert between decimals and percents.

styles.scss
@use "sass:math";
@use "sass:meta";

.ops {
  --div: #{meta.inspect(math.div(15px, 30px))};
  --pct: #{meta.inspect(0.5 * 100%)};
  --dec: #{meta.inspect(math.div(50%, 100%))};
  --rate: #{meta.inspect(math.div(5px, 2s))};
}

How It Works

Same units cancel in math.div(15px, 30px). Different units build a rate like 2.5px/s. Percent math stays unit-aware.

Example 4 — Unit Ratio for Transitions

Official-style speed ratio: seconds per pixel times distance.

styles.scss
@use "sass:math";

$transition-speed: math.div(1s, 50px);

@mixin move($left-start, $left-stop) {
  position: absolute;
  left: $left-start;
  transition: left ($left-stop - $left-start) * $transition-speed;

  &:hover {
    left: $left-stop;
  }
}

.slider {
  @include move(10px, 120px);
}

How It Works

Distance is 110px. Multiplied by 1s / 50px, the px units cancel and leave 2.2s.

Example 5 — Everyday Layout Math

Scale width, padding, and font size from a shared base token.

styles.scss
@use "sass:math";

$base: 16px;
$pad: 8px;

.box {
  width: $base * 10;
  padding: $pad;
  margin-top: $base - $pad;
  font-size: math.div($base * 3, 2);
}

How It Works

One base size drives several properties. Multiplication, subtraction, and math.div all resolve before CSS is written.

🚀 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.

⚠️ 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.

💡 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

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
🔢 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.

Conclusion

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.

Continue with string operators or browse relational operators.

Next: Sass String Operators

Concatenate strings with +, and prefer #{} interpolation.

String operators →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful