math.log($number, $base: null) returns the logarithm of $number with respect to $base. If $base is null (the default), Sass calculates the natural log (base e). Both $number and $base must be unitless. Load it with @use "sass:math" on Dart Sass 1.25+.
Pattern: ensure unitless input → choose natural log or a base → use the result as a scale exponent or step count. Related: math.pow, math.sqrt, math.div.
Reference
Bases and Inputs
How the second argument changes the result:
Call
Meaning
Result
math.log(10)
Natural log (base e)
2.302585093
math.log(10, 10)
Log base 10
1
math.log(8, 2)
Log base 2
3
math.log(math.$e)
ln(e)
1
Input with units
Not allowed
Error
math.$e.
The sass:math module also exposes the constant math.$e (≈ 2.7182818285) when you want an explicit natural-log base.
Natural log by default; pass a second arg for another base.
Unitless only for both number and base.
Inverse of math.pow for the same base.
Dart Sass 1.25+ via @use "sass:math".
One line: when a unitless Sass number needs a logarithm, call math.log($number) or math.log($number, $base).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Ensure $number (and $base) are unitless
3. Omit $base for natural log; pass a base for log_b
4. Pair with math.pow for round-trips
5. Use math.is-unitless before logging unknown tokens
Frequently Asked Questions
math.log($number, $base: null) returns the logarithm of $number. If $base is null (the default), it returns the natural logarithm (base e). Example: math.log(10) is about 2.302585093; math.log(10, 10) is 1.
Add @use "sass:math"; then call math.log($number) or math.log($number, $base). Requires Dart Sass 1.25+.
No. Official docs require $number and $base to be unitless. Strip units first, for example with math.div($a, $b) when both share a unit. Guard with math.is-unitless().
Official docs expose this as math.log() on sass:math. Prefer the module form with @use "sass:math".
They are inverse ideas: if y = math.log(x, b), then math.pow(b, y) recovers x (within floating-point precision). Pair them for scale exponents and growth math.
Natural log uses base e (about 2.718…). In Sass, math.log(10) with no second argument is ln(10). You can also write math.log($n, math.$e) for the same idea explicitly.