Home Sass Math math.pow() Sass math.pow() Definition
Definition and Usage math.pow($base, $exponent) raises $base to the power of $exponent. Both arguments must be unitless . Load it with @use "sass:math" on Dart Sass 1.25+ .
Official samples. math.pow(10, 2) → 100 · math.pow(100, math.div(1, 3)) → 4.6415888336 · math.pow(5, -2) → 0.04.
Inverse of log. Pair with math.log : if y = math.pow(b, x), then math.log(y, b) recovers x (within floating-point precision).
Unitless only. Do not pass px into math.pow. Compute the unitless factor first, then multiply by a length: 16px * math.pow(1.25, 3).
Syntax
Syntax @use "sass:math";
math.pow($base, $exponent); //=> unitless number
math.pow(10, 2); // 100
math.pow(100, math.div(1, 3)); // 4.6415888336 (cube root)
math.pow(5, -2); // 0.04
math.pow(9, 0.5); // 3 (same idea as math.sqrt(9))
// Apply units after the power
16px * math.pow(1.25, 2); // 25px
// Module API — prefer math.pow after @use "sass:math" Pattern: keep scale math unitless → call math.pow → multiply by a length when CSS needs units. Related: math.log , math.sqrt , math.div .
Code
SCSS Examples Examples target Dart Sass 1.25+ with @use "sass:math". Open View Compiled CSS for verified output (matches official Sass docs samples).
1. Integer power 2. Fractional root 3. Negative 4. Round-trip 5. CSS scale Example 1 — Official Docs Sample (Integer Power) Raise 10 to the power of 2.
@use "sass:math";
@debug math.pow(10, 2); // 100
.basic {
--a: #{math.pow(10, 2)};
} How It Works Base and exponent are both unitless.10² is 100.Result stays unitless .Matches the official Sass docs sample.Example 2 — Official Docs Sample (Cube Root) A fractional exponent acts as a root.
@use "sass:math";
@debug math.pow(100, math.div(1, 3)); // 4.6415888336
.root {
--b: #{math.pow(100, math.div(1, 3))};
} .root {
--b: 4.6415888336;
} How It Works math.div(1, 3) builds a unitless one-third.Exponent 1/3 means cube root.Result is about 4.6415888336 .Matches the official Sass docs sample.Example 3 — Official Docs Sample (Negative Exponent) Negative powers invert the base.
@use "sass:math";
@debug math.pow(5, -2); // 0.04
.neg {
--c: #{math.pow(5, -2)};
} How It Works 5⁻² means 1 / 5².1 / 25 is 0.04.Still unitless on both sides.Matches the official Sass docs sample.Example 4 — Round-Trip with math.log / math.sqrt Power undoes a same-base log; half-power matches sqrt.
@use "sass:math";
.roundtrip {
--back: #{math.pow(10, math.log(10, 10))};
--sqrt: #{math.pow(9, 0.5)};
--sqrt2: #{math.sqrt(9)};
} .roundtrip {
--back: 10;
--sqrt: 3;
--sqrt2: 3;
} How It Works log₁₀(10) is 1, then 10¹ recovers 10.pow(9, 0.5) is the square root.math.sqrt(9) matches that result.Use sqrt when the intent is specifically a square root.Example 5 — Modular Scale into CSS Keep the power unitless, then use it as a factor or opacity.
@use "sass:math";
$base: 2;
$exp: 3;
.scale {
--steps: #{math.pow($base, $exp)};
opacity: math.pow(0.5, 2);
font-size: 16px * math.pow(1.25, 2);
} .scale {
--steps: 8;
opacity: 0.25;
font-size: 25px;
} How It Works 2³ becomes step count 8.0.5² becomes opacity 0.25.Units attach after the power: 16px * 1.25² → 25px.Classic pattern for modular type scales. Edge Cases & Pitfalls Most pow bugs are feeding units into the helper, or forgetting negative exponents invert.
units Unitless base and exponent Multiply by a length after math.pow. Check with math.is-unitless .
neg Negative exponents invert math.pow(5, -2) is 0.04, not a negative length.
root Prefer math.sqrt for square roots math.pow($n, 0.5) works, but math.sqrt states the intent clearly.
module Module-only helper Use math.pow after @use "sass:math".
Toolchain
Sass Support Prefer the module form with Dart Sass 1.25+.
API Status math.pow()Dart Sass 1.25+ via @use "sass:math" Input Unitless $base and unitless $exponent Return type Unitless number LibSass / Ruby Sass No modern sass:math pow
Compile with the Dart Sass CLI .
Remember
Key Takeaways Raises a unitless base to a unitless exponent.
Fractional = roots ; negative = reciprocal power.
Inverse of math.log for the same base.
Apply CSS units after the power calculation.
One line: when a unitless Sass number needs an exponent, call math.pow($base, $exponent).
Practice
Compile Notes Practical checklist:
1. @use "sass:math"
2. Keep $base and $exponent unitless
3. Use fractional exponents for roots; negative for reciprocals
4. Multiply by a length after pow when CSS needs units
5. Pair with math.log for modular-scale round-trips Frequently Asked Questions What does Sass math.pow() do? math.pow($base, $exponent) raises $base to the power of $exponent. Example: math.pow(10, 2) is 100; math.pow(5, -2) is 0.04.
How do I use math.pow() with @use? Add @use "sass:math"; then call math.pow($base, $exponent). Requires Dart Sass 1.25+.
Can math.pow() take CSS units like px? No. Official docs require $base and $exponent to be unitless. Multiply the result by a length afterward, for example 16px * math.pow(1.25, 3).
Is there a global pow() in Sass? Official docs expose this as math.pow() on sass:math. Prefer the module form with @use "sass:math".
How is math.pow related to math.log? They are inverse ideas: if y = math.pow(b, x), then math.log(y, b) recovers x (within floating-point precision). Pair them for modular scales.
How do fractional and negative exponents work? Fractional exponents are roots—math.pow(100, math.div(1, 3)) is the cube root of 100. Negative exponents invert—math.pow(5, -2) is 1 / 5² = 0.04.
Next: Sass math.random() Generate a random decimal or whole number at compile time.
math.random() → About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion