Sass math.div()

Beginner
10 min read
Updated: Nov 2026
5 examples
Dart Sass 1.33+

Definition and Usage

math.div($number1, $number2) divides the first number by the second. Shared units cancel. Units only in the first stay in the numerator; units only in the second move to the denominator. Prefer it over slash / division. Load it with @use "sass:math" on Dart Sass 1.33+.

Official samples.

math.div(1, 2) → 0.5 · math.div(100px, 5px) → 20 · math.div(100px, 5) → 20px.

Why not /?

Slash is ambiguous in Sass (division vs CSS separators such as font: 16px/1.5). Slash division is deprecated. Use math.div for math, and list.slash when you need a slash-separated list.

Legacy string behavior.

Official docs: for compatibility, math.div still mirrors some deprecated / behaviors (including string concatenation). Do not rely on that in new stylesheets.

Syntax

SCSS
@use "sass:math";

math.div($number1, $number2); //=> number

math.div(1, 2);         // 0.5
math.div(100px, 5px);   // 20      (px cancels)
math.div(100px, 5);     // 20px
math.div(100px, 5s);    // complex unit (often calc() today)

// Prefer math.div over deprecated slash division:
// $x: 100px / 5px;  // avoid

// Module API — prefer math.div after @use "sass:math"

Pattern: divide two Sass numbers → let shared units cancel → use the unitless result as a ratio, or keep leftover units as a CSS length/rate.

Units After Division

How units move through math.div:

CallResult
math.div(1, 2)0.5 (unitless)
math.div(100px, 5px)20 (shared px cancels)
math.div(100px, 5)20px
math.div(100px, 5s)Complex unit — modern Dart Sass often emits calc(20px / 1s)
math.div(24px, 16px)1.5 (unitless line-height ratio)
Docs vs current CSS.

Official docs historically show 20px/s for math.div(100px, 5s). Current Dart Sass may serialize that as calc(20px / 1s). Trust the compiled CSS from your compiler.

SCSS Examples

Examples target Dart Sass 1.33+ with @use "sass:math". Open View Compiled CSS for verified output (aligned with official Sass docs).

Example 1 — Official Docs Sample (Unitless)

Plain numeric division.

SCSS
@use "sass:math";

@debug math.div(1, 2); // 0.5

.basic {
  --a: #{math.div(1, 2)};
}

How It Works

  1. Both args are unitless.
  2. 1 / 2 becomes 0.5.
  3. No units to cancel or keep.
  4. Matches the official Sass docs sample.

Example 2 — Shared Units Cancel

Official sample: dividing matching lengths yields a unitless ratio.

SCSS
@use "sass:math";

@debug math.div(100px, 5px); // 20

.cancel {
  --b: #{math.div(100px, 5px)};
}

How It Works

  1. Both sides use px.
  2. Shared unit cancels.
  3. Result is unitless 20.
  4. Useful for column counts and aspect ratios.

Example 3 — Keep the Numerator Unit

Official sample: dividing by a unitless number keeps px.

SCSS
@use "sass:math";

@debug math.div(100px, 5); // 20px

.keep {
  --c: #{math.div(100px, 5)};
}

How It Works

  1. Numerator has px.
  2. Denominator is unitless 5.
  3. Nothing cancels — result stays 20px.
  4. Common when splitting a length into equal parts.

Example 4 — Different Unit Families

Official docs show 20px/s; current Dart Sass often emits calc().

SCSS
@use "sass:math";

@debug math.div(100px, 5s); // docs: 20px/s

.complex {
  --d: #{math.div(100px, 5s)};
}

How It Works

  1. px stays in the numerator.
  2. s moves to the denominator.
  3. Modern Dart Sass may wrap the complex unit in calc().
  4. Concept matches the official docs sample.

Example 5 — Slash List vs Division

Keep CSS font shorthand separate from real division.

SCSS
@use "sass:math";

$w: 320px;
$col: 4;

.slash {
  font: 16px / 1.5 sans-serif; // CSS separator, not math.div
  line-height: math.div(24px, 16px);
}

.grid {
  width: math.div($w, $col);
}

How It Works

  1. Font slash stays a CSS separator.
  2. math.div(24px, 16px) cancels to 1.5.
  3. Grid width is 320px / 4 → 80px.
  4. Clear split between list slash and numeric division.

Edge Cases & Pitfalls

Most div bugs are still using slash for math, or expecting units that already canceled.

slash

Do not divide with /

Slash division is deprecated. Use math.div for math and list.slash for separators.

units

Shared units disappear

math.div(100px, 5px) is unitless 20, not 20px.

calc

Complex units may become calc()

Mixed families like px/s can serialize differently across Dart Sass versions.

legacy

Avoid string-slash tricks

Official docs warn that compatibility string behavior will go away — do not use it in new code.

Sass Support

Prefer the module form with Dart Sass 1.33+.

APIStatus
math.div()Dart Sass 1.33+ via @use "sass:math"
Slash / divisionDeprecated — migrate to math.div
UnitsShared units cancel; leftovers stay or form complex units
LibSass / Ruby SassNo modern math.div

Compile with the Dart Sass CLI.

Key Takeaways

  • Modern division — prefer math.div over slash /.
  • Shared units cancel; leftover units stay on the result.
  • Slash for CSS lists is different — use list.slash when needed.
  • Dart Sass 1.33+ via @use "sass:math".

One line: when two Sass numbers must be divided, call math.div($number1, $number2).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Call math.div($a, $b) instead of $a / $b
3. Expect shared units to cancel
4. Keep CSS slash lists separate (font, list.slash)
5. Check compiled CSS for complex units (may be calc())

Frequently Asked Questions

math.div($number1, $number2) divides the first number by the second. Shared units cancel. Examples: math.div(1, 2) is 0.5; math.div(100px, 5px) is 20; math.div(100px, 5) is 20px. Dividing mixed unit families may serialize as calc() in modern Dart Sass.
Add @use "sass:math"; then call math.div($a, $b). Requires Dart Sass 1.33.0 or newer for the math.div API documented on sass:math.
Slash / in Sass is ambiguous (division vs CSS separators like font shorthand). Division with / is deprecated. Prefer math.div() for clear, future-safe division.
Units that appear in both numbers cancel. Units only in the first stay in the numerator; units only in the second move to the denominator. That is why 100px / 5px becomes unitless 20, while 100px / 5 stays 20px.
No. math.div() is the recommended modern division helper. Official docs warn that it still mirrors some legacy / behaviors (including string concatenation) for compatibility, and that string-slash behavior should not be used in new stylesheets.
Built-in modules with @use need Dart Sass. math.div() itself is available since Dart Sass 1.33.0. LibSass and Ruby Sass do not provide sass:math the same way.

Next: Sass math.floor()

Round a number down to the next whole value.

math.floor() →

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.

8 people found this page helpful