CSS Reference ยท Functions
Exponential functions: pow(), sqrt(), hypot(), log(), exp()
Reference for the CSS exponential functions pow, sqrt, hypot, log and exp: arguments, return types, modular type scales and live examples.
The exponential math functions compute powers, roots and logarithms. pow() raises a number to a power, sqrt() takes a square root, hypot() computes the length of a vector, log() and exp() work with logarithms. They are most useful for type scales, geometric spacing and distance calculations.
h2 { font-size: calc(1rem * pow(1.25, 3)); /* 1.953rem */ }
Try it
Change --ratio to 1.5 and every step grows with the same proportion.
Syntax
pow( <number>, <number> ) /* base raised to exponent */ sqrt( <number> ) /* square root */ hypot( <calc-sum># ) /* sqrt of the sum of squares */ log( <number> [, <number>]? ) /* logarithm; natural log if no base given */ exp( <number> ) /* e raised to the power */
Syntax and arguments
| Function | Description |
|---|---|
pow(a, b) |
a to the power b. Both must be plain numbers; pow(2, 3) is 8. |
sqrt(n) |
Square root of a number. sqrt(16) is 4. |
hypot(a, b, ...) |
The square root of the sum of squares. All arguments must have the same type, and the result has that type: hypot(3px, 4px) is 5px. |
log(n) |
Natural logarithm. With a second argument it is the logarithm to that base: log(8, 2) is 3. |
exp(n) |
e raised to n; exp(1) is about 2.718. |
All of them can be nested in calc() and combined with other math functions.
Usage notes
pow,sqrt,logandexptake numbers only. Multiply the result by a unit:calc(pow(2, 4) * 1px)is16px. Writingpow(2px, 2)is invalid.hypot()accepts lengths, which is handy for the diagonal of a box or the distance between two offsets.- Modular scales. Define
--stepper heading level and computepow(var(--ratio), var(--step)). Changing one ratio resizes the whole system. - Geometric spacing.
calc(pow(2, var(--n)) * 4px)produces 4, 8, 16, 32 and so on. - Invalid math. Results that are not real numbers, such as
sqrt(-1)orlog(-1), becomeNaNand the declaration is invalid at computed-value time. - Readability. Document the formula next to the custom properties; formulas like these are hard to guess later.
Browser support
These functions arrived together with the other newer math functions and are supported in current versions of the major browsers; check a compatibility table before relying on them, and add a static fallback.