CKTIS / CSS
pow(): raising a number to a power
Build a numeric scale with a base and exponent, then attach the unit required by the CSS property.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
width: calc(10px * pow(2, 3));pow(base, exponent) returns the base raised to the exponent. Both comma-separated arguments must resolve to unitless numbers; the result is also a number. This is useful for proportional scales, such as a base size multiplied by a ratio raised to a step number. pow(2, 3) is 8, not 6: it is exponentiation, not multiplication.
Negative and fractional exponents are possible: pow(2, -1) is one half and pow(4, 0.5) is 2. A negative base with an integer exponent can have a real result, but a finite negative base with a finite non-integer exponent produces NaN. Keep dimensions outside the power calculation: pow(2px, 3) is not a CSS length calculation. Multiply the unitless result by a length in calc() when a width is needed.
The example computes four widths from a 10px base: 80px for 2 cubed, 20px for the square root of 4, 5px for 2 to the power -1, and 40px for (-2) squared. It also checks that the tested length argument is rejected while the numeric form is supported. Reading the computed widths confirms evaluation, beyond a syntax-only CSS.supports() check.
Examples
const box=document.createElement('div');document.body.append(box);
const width=value=>{box.style.width=value;return getComputedStyle(box).width};
const cube=width('calc(10px * pow(2, 3))');
const root=width('calc(10px * pow(4, 0.5))');
const reciprocal=width('calc(10px * pow(2, -1))');
const signed=width('calc(10px * pow(-2, 2))');
console.log('cube='+cube+'; root='+root+'; reciprocal='+reciprocal+'; signed='+signed+'; length-argument='+CSS.supports('width','calc(1px * pow(2px, 3))')+'; syntax='+CSS.supports('width','calc(1px * pow(2, 3))'));Result
cube=80px; root=20px; reciprocal=5px; signed=40px; length-argument=false; syntax=true
Verified in Chromium 157.0.8103.51. For older browsers, provide a preceding width without pow() or use @supports; this test does not establish support in every browser.