CKTIS / CSS
sqrt(): a numeric square root with explicit units
Calculate a square root from a number, then attach a length only where the receiving property needs one.
Version: CSS Modules
Syntax
transform: translateX(calc(sqrt(2) * 10px));The CSS math function sqrt() accepts one calculation resolving to a number and returns a number. For a positive input it returns the nonnegative square root. It does not directly take a length such as 9px: calculate with numbers and multiply by a length afterwards. For a vector length whose components already carry units, hypot() is the separate unit-preserving operation.
A negative input produces NaN rather than a usable real root. Positive infinity remains positive infinity, and negative zero is preserved by the mathematical operation. Those special results still pass through the receiving property’s rules. A successful CSS.supports() check only establishes syntactic acceptance; it does not prove that a negative argument will produce a useful opacity or distance.
The example sets opacity from the square root of 0.25 and measures 0.5. It then multiplies the square root of 2 by 10px, producing a computed horizontal translation reported as 14.1421 after rounding. The checks reject a direct length argument and two arguments, but accept the syntax of the negative-number case. That last check deliberately does not measure how the property resolves NaN.
Examples
const box = document.createElement('div');
document.body.append(box);
box.style.opacity = 'sqrt(0.25)';
console.log('opacity:', getComputedStyle(box).opacity);
box.style.transform = 'translateX(calc(sqrt(2) * 10px))';
const matrix = new DOMMatrix(getComputedStyle(box).transform);
console.log('distance:', Number(matrix.m41.toFixed(4)));
console.log('length argument:', CSS.supports('width','sqrt(9px)'));
console.log('negative parses:', CSS.supports('opacity','sqrt(-1)'));
console.log('two arguments:', CSS.supports('opacity','sqrt(1,4)'));
box.remove();Result
opacity: 0.5 distance: 14.1421 length argument: false negative parses: true two arguments: false
The numeric result is read from the browser’s computed style and transformation matrix. No JavaScript square-root calculation substitutes for CSS evaluation; the negative case is a support probe only.