CKTIS / CSS
hypot() — CSS vector magnitude
`hypot()` returns the magnitude of a vector formed by one or more calculations with a consistent type.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
hypot( <calc-sum># )hypot() returns the magnitude of a vector formed by one or more calculations with a consistent type.
hypot(30px, 40px) sets width to 50px; hypot(30%, 40%) in a 200 px container gives 100px; one-argument hypot(-12px) gives absolute value 12px. Inconsistent hypot(10px, 1deg) returns false.
Grammar: hypot( <calc-sum># ).
The result corresponds to sqrt(A² + …) and retains the arguments’ common type: numbers, compatible dimensions, or percentages. A length cannot be mixed with an angle. Because the function directly accepts dimensions, it is useful for diagonals and transform distances; one argument acts as absolute value, and any infinite argument produces positive infinity.
Examples
const host=document.createElement('div');host.style.cssText='width:200px;font-size:10px';document.body.append(host);
const used=value=>{const box=document.createElement('div');box.style.width=value;host.append(box);return getComputedStyle(box).width};
const triangle=used('hypot(30px, 40px)');
const percentage=used('hypot(30%, 40%)');
const absolute=used('hypot(-12px)');
const inconsistent=CSS.supports('width','hypot(10px, 1deg)');
console.log('triangle='+triangle+'; percentage='+percentage+'; single-negative='+absolute+'; inconsistent-types='+inconsistent);Result
triangle=50px; percentage=100px; single-negative=12px; inconsistent-types=false
`hypot()` returns the magnitude of a vector formed by one or more calculations with a consistent type.