MDN self-hosted library · e01.org

CSSNumericValue: div() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const half = CSS.px(24).div(2);
console.log(half.toString()); // "12px"
js
const ratio = CSS.px(10).div(CSS.px(2));
console.log(ratio.toString()); // "calc(10px / 2px)"

const mathProduct = CSS.px(24).div(CSS.percent(4));
console.log(mathProduct.toString()); // "calc(24px / 4%)"
js
try {
  CSS.px(10).div(0);
} catch (e) {
  console.log(e instanceof RangeError); // true
}

console.log(CSS.px(10).div(CSS.px(0)).toString()); // "calc(10px / 0px)"