math.div() is the modern division helper in the sass:math module. It replaces ambiguous slash / division, cancels shared units, and runs at compile time. This page covers unit rules, Dart Sass 1.33+, migration from /, and five compiled examples.
01
Concept
Divide a ÷ b
02
Module
@use "sass:math"
03
Units
Cancel & keep
04
Since
Dart Sass 1.33+
05
Replaces
Slash / division
06
Practice
5 examples
Concept
What Is math.div()?
Division asks “how many times does this fit into that?” math.div($number1, $number2) returns that quotient at compile time. Official docs place it under Other Functions and document it as the clear alternative to slash / division.
math.div(1, 2) → 0.5
math.div(100px, 5px) → 20 (units cancel)
math.div(100px, 5) → 20px (length kept)
math.div(100px, 5s) → 20px/s (compound unit)
💡
Beginner tip
math.div() itself is not deprecated—it is the recommended fix. Slash / used as division is what Sass is phasing out, because the same character also appears in CSS lists and font shorthand.
Foundation
📝 Syntax
Load the math module, then call the function:
styles.scss
@use "sass:math";
math.div($number1, $number2)
Parameters
Parameter
Type
Required
Description
$number1
Number
Yes
Dividend—the value being divided.
$number2
Number
Yes
Divisor—the value you divide by (must not be zero).
Return value
Type
Meaning
Number
The quotient. Units may cancel, stay, or become a compound form like px/s.
Modules
📦 Loading sass:math
math.div() lives on the module API—load sass:math with @use. There is no separate “global div()” documented the way older helpers like abs() still expose.
styles.scss
// Recommended — namespaced
@use "sass:math";
$ratio: math.div(24px, 16px);
// Optional — bring members into the current namespace
@use "sass:math" as *;
$ratio: div(24px, 16px);
// Optional — custom namespace
@use "sass:math" as m;
$ratio: m.div(24px, 16px);
⚠️
Put @use first
Keep @use "sass:math"; near the top of the file. Need Dart Sass 1.33+ for math.div as documented on the math module.
Numbers
📏 How Units Work
Official docs describe the rules clearly: shared units cancel. Leftover units from the first argument stay in the numerator; leftover units from the second move into the denominator.
Call
Result
Notes
math.div(1, 2)
0.5
Both unitless
math.div(100px, 5px)
20
px cancels → unitless ratio
math.div(100px, 5)
20px
Only numerator had units
math.div(100px, 5s)
20px/s
Compound unit (not a plain CSS length)
math.div(24px, 16px)
1.5
Common scale / opacity ratio
⚠️
Compound units and CSS
Values like 20px/s are valid Sass numbers for further math, but they are not valid plain CSS lengths. Do not interpolate them into properties that expect px or %. Inspect them with @debug or math.unit().
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a plain number (or length)—no math.div() call remains.
Implementation
math.div()
Notes
Dart Sass 1.33+
Yes
Preferred; needs @use "sass:math"
Dart Sass < 1.33
No (module form)
Upgrade Dart Sass to use math.div
LibSass / Ruby Sass
No module API
Use Dart Sass for modern division
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import math
@use "sass:math";
Divide numbers
math.div($a, $b)
Unitless half
math.div(1, 2) → 0.5
Cancel matching units
math.div(100px, 5px) → 20
Keep a length
math.div(100px, 5) → 20px
Scale ratio
math.div(24px, 16px) → 1.5
Replace slash division
$a / $b → math.div($a, $b)
Debug while learning
@debug math.div(100px, 5px);
Compare
📋 math.div() vs Slash /
Same arithmetic idea—different future. Prefer the function for new SCSS.
math.div($a, $b)
$a / $b
Status
Modern, recommended
Division use is deprecated
Clarity
Always means divide
Also used in CSS lists / font shorthand
Module
Needs sass:math
Built-in operator (legacy)
New code?
Yes
Migrate away
⚠️
Heads up from the docs
For compatibility, math.div still matches some legacy / behaviors—including concatenating two strings with a / between them. That string behavior will be removed eventually and should not be used in new stylesheets. Divide numbers, not strings.
Canceling px gives a reusable ratio. Multiplying or dividing that ratio against the base keeps the type system consistent.
Example 5 — Migrate Off Slash Division
Same results, clearer intent with math.div.
styles.scss
@use "sass:math";
// Old (division with / is deprecated)
// $half: 48px / 2;
// $ratio: 24px / 16px;
// Modern
$half: math.div(48px, 2);
$ratio: math.div(24px, 16px);
.box {
width: $half;
opacity: math.div($ratio, 2); // 0.75
}
📤 Compiled CSS:
.box {
width: 24px;
opacity: 0.75;
}
How It Works
Readers immediately see division. You also avoid slash ambiguity with CSS separators, and you stay on the supported Sass path.
Applications
🚀 Real-World Use Cases
Opacity and ratios — cancel matching units into unitless 0–1 values.
Type and spacing scales — derive steps from a base length.
Responsive math tokens — compute fixed halves, thirds, and gutters at compile time.
Migrating legacy SCSS — replace deprecated / division across a codebase.
Percentage helpers — feed unitless ratios into math.percentage().
Pre-log / pre-pow cleanup — strip units with matching division before unitless-only helpers.
🧠 How Compilation Works
1
Write SCSS
Call math.div($a, $b) after @use.
Source
2
Cancel shared units
Matching units drop out; leftovers form the result unit.
Units
3
Compute the quotient
Sass divides the magnitudes and attaches remaining units.
Divide
4
✓
Plain CSS ships
The browser receives the finished number or length.
Watch Out
⚠️ Common Pitfalls
Still using / for division — migrate to math.div().
Emitting compound units into CSS — px/s is not a valid length property value.
Dividing by zero — guard divisors in mixins and maps.
String slash tricks — do not use math.div to concatenate strings; that legacy behavior is going away.
Old Dart Sass — need 1.33+ for documented math.div.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:math" and math.div() in new SCSS
Cancel matching units when you need a ratio
Keep numerator units when you want a scaled length
Prefer Dart Sass 1.33+
Pair with is-unitless / unit while learning
❌ Don’t
Rely on slash / for Sass division in new code
Ship intermediate px/s-style values into ordinary CSS props
Use math.div as a string joiner
Expect the browser to re-evaluate math.div
Rely on LibSass for sass:math
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about math.div()
Modern division—shared units cancel, slash / is legacy.
5
Core concepts
📝01
Call
div(a, b)
API
📦02
Module
sass:math
@use
📏03
Units
cancel / keep
Rule
⚡04
Replaces
slash /
Migrate
✓05
Since
Dart Sass 1.33+
Tooling
❓ 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; math.div(100px, 5s) is 20px/s.
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.
Did you know?
Official Sass docs list math.div under Other Functions and call out that it returns the same results as the old / division operator for numbers—including unit canceling—while giving you a name that cannot be confused with CSS slash separators.
math.div() is the clear, modern way to divide in Sass. Shared units cancel into ratios, leftover units stay on the result, and slash / division can retire from your new stylesheets. Prefer Dart Sass 1.33+ with @use "sass:math".