This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The toString() stringifier of the DOMMatrixReadOnly interface returns the value of the matrix as a string in the form of a matrix() or matrix3d() CSS transform function; comma-separated lists of 6 or 16 coordinate values, prepended by "matrix( or "matrix3d( respectively, appended by )".
For a 2D matrix, the elements a through f are listed, for a total of six values and the form matrix(a, b, c, d, e, f). See the matrix() CSS function for details on this syntax.
For a 3D matrix, the returned string contains all 16 elements and takes the form matrix3d(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44). See the CSS matrix3d() function for details on the 3D notation's syntax.
toString()
None.
A string; the values of the list separated by commas, within matrix() or matrix3d() function syntax.
const matrix = new DOMMatrixReadOnly(); console.log(matrix.translate(20, 30).toString()); // matrix(1, 0, 0, 1, 20, 30) console.log(matrix.translate(30, 40, 50).toString()); // matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 30, 40, 50, 1) console.log(matrix.skewY(15).skewX(5).rotate(3).translate(20, 50).toString()); // matrix(1.003, 0.321, 0.035, 1.01, 21.816, 56.824) console.log( matrix.skewY(15).skewX(5).rotate(3).translate(20, 50, 60).toString(), ); // matrix3d(1.003, 0.321, 0, 0, 0.0350, 1.008, 0, 0, 0, 0, 1, 0, 21.816, 56.824, 60, 1)
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
toString |
61 | 79 | 33 | 48 | 11 | 61 | 33 | 45 | 11 | 8.0 | 61 | 11 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrixReadOnly/toString