MDN self-hosted library · e01.org

CSSTransformValue: toMatrix() method

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

js
const transform = new CSSTransformValue([
  new CSSTranslate(CSS.px(10), CSS.px(20)),
  new CSSScale(2, 3),
]);

const matrix = transform.toMatrix();
console.log(matrix.a, matrix.d); // 2 3
console.log(matrix.e, matrix.f); // 10 20
js
const transform = new CSSTransformValue([
  new CSSTranslate(CSS.percent(50), CSS.px(20)),
]);

try {
  transform.toMatrix();
} catch (e) {
  console.log(e); // TypeError
}