Sass math.div() Function

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:math · Dart Sass 1.33+

What You’ll Learn

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

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.

📝 Syntax

Load the math module, then call the function:

styles.scss
@use "sass:math";

math.div($number1, $number2)

Parameters

ParameterTypeRequiredDescription
$number1NumberYesDividend—the value being divided.
$number2NumberYesDivisor—the value you divide by (must not be zero).

Return value

TypeMeaning
NumberThe quotient. Units may cancel, stay, or become a compound form like px/s.

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

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

CallResultNotes
math.div(1, 2)0.5Both unitless
math.div(100px, 5px)20px cancels → unitless ratio
math.div(100px, 5)20pxOnly numerator had units
math.div(100px, 5s)20px/sCompound unit (not a plain CSS length)
math.div(24px, 16px)1.5Common 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().

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a plain number (or length)—no math.div() call remains.

Implementationmath.div()Notes
Dart Sass 1.33+YesPreferred; needs @use "sass:math"
Dart Sass < 1.33No (module form)Upgrade Dart Sass to use math.div
LibSass / Ruby SassNo module APIUse Dart Sass for modern division

⚡ Quick Reference

GoalCode
Import math@use "sass:math";
Divide numbersmath.div($a, $b)
Unitless halfmath.div(1, 2)0.5
Cancel matching unitsmath.div(100px, 5px)20
Keep a lengthmath.div(100px, 5)20px
Scale ratiomath.div(24px, 16px)1.5
Replace slash division$a / $bmath.div($a, $b)
Debug while learning@debug math.div(100px, 5px);

📋 math.div() vs Slash /

Same arithmetic idea—different future. Prefer the function for new SCSS.

math.div($a, $b)$a / $b
StatusModern, recommendedDivision use is deprecated
ClarityAlways means divideAlso used in CSS lists / font shorthand
ModuleNeeds sass:mathBuilt-in operator (legacy)
New code?YesMigrate 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.

📋 Division Friends in sass:math

GoalHelper
Divide two numbersmath.div($a, $b)
Turn a unitless ratio into %math.percentage(math.div($a, $b))
Confirm the result is unitlessmath.is-unitless()
Read leftover units as textmath.unit()

Examples Gallery

Each example uses @use "sass:math". Open View Compiled CSS to see what Dart Sass emits.

📚 Getting Started

Official-style divisions from the Sass docs.

Example 1 — Basic math.div()

Unitless numbers divide into a plain decimal.

styles.scss
@use "sass:math";

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

.fade {
  opacity: math.div(1, 2);
}

How It Works

1 ÷ 2 becomes 0.5 at compile time, so the browser only sees a finished opacity value.

Example 2 — Matching Units Cancel

Dividing length by length produces a unitless ratio.

styles.scss
@use "sass:math";

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

.meter {
  --ratio: #{math.div(100px, 5px)};
  opacity: math.div(40px, 100px);
}

How It Works

Shared px units cancel, leaving a bare number—perfect for ratios, scales, and opacity.

📈 Practical Patterns

Keep lengths, build scales, and migrate off slash division.

Example 3 — Keep the Numerator Unit

Divide a length by a unitless number to shrink it.

styles.scss
@use "sass:math";

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

.card {
  width: math.div(100px, 5);
  padding: math.div(32px, 2);
}

How It Works

Only the first value had units, so the result stays a length: 20px and 16px.

Example 4 — Design-Token Scale

Build a type scale from a base size and a ratio.

styles.scss
@use "sass:math";

$base: 16px;
$step: 24px;
$ratio: math.div($step, $base); // 1.5

.title {
  font-size: $base * $ratio; // 24px
}

.caption {
  font-size: math.div($base, $ratio); // ~10.666px
  letter-spacing: math.div(1px, 16);  // 0.0625px
}

How It Works

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
}

How It Works

Readers immediately see division. You also avoid slash ambiguity with CSS separators, and you stay on the supported Sass path.

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

⚠️ Common Pitfalls

  • Still using / for division — migrate to math.div().
  • Emitting compound units into CSSpx/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.

💡 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

Key Takeaways

Knowledge Unlocked

Five things to remember about math.div()

Modern division—shared units cancel, slash / is legacy.

5
Core concepts
📦 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.

Conclusion

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

Continue with math.floor(), math.is-unitless(), or math.unit().

More Sass Math

Continue with rounding down in the math module.

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.

5 people found this page helpful