The DOMMatrix interface represents 4×4 matrices, suitable for 2D and 3D operations including rotation and translation. It is a mutable version of the DOMMatrixReadOnly interface.

WebKitCSSMatrix and SVGMatrix are aliases to DOMMatrix.

This interface should be available inside web workers, though some implementations don't allow it yet.

A Boolean whose value is true if the matrix is the identity matrix. The identity matrix is one in which every value is 0except those on the main diagonal from top-left to bottom-right corner (in other words, where the offsets in each direction are equal).

Double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.

Double-precision floating-point values representing the components of a 4×4 matrix which are required in order to perform 2D rotations and translations. These are aliases for specific components of a 4×4 matrix, as shown below.

2D

3D equivalent

a

m11

b

m12

c

m21

d

m22

e

m41

f

m42

Instance methods

This interface includes the following methods, as well as the methods it inherits from DOMMatrixReadOnly.

Modifies the matrix by post-multiplying it with the specified DOMMatrix. This is equivalent to the dot product A⋅B, where matrix A is the source matrix and B is the matrix given as an input to the method. Returns itself.

Modifies the matrix by pre-multiplying it with the specified DOMMatrix. This is equivalent to the dot product B⋅A, where matrix A is the source matrix and B is the matrix given as an input to the method. Returns itself.

Modifies the matrix by applying the specified scaling on the X, Y, and Z axes, centered at the given origin. By default, the Y and Z axes' scaling factors are both 1, but the scaling factor for X must be specified. The default origin is (0, 0, 0). Returns itself.

Modifies the matrix by applying the specified scaling factors, with the center located at the specified origin. Also returns itself. By default, the scaling factor is 1 for all three axes, and the origin is (0, 0, 0). Returns itself.

Creates a new mutable DOMMatrix object given an array of single-precision (32-bit) floating-point values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, a TypeError exception is thrown.

Creates a new mutable DOMMatrix object given an array of double-precision (64-bit) floating-point values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, a TypeError exception is thrown.

Creates a new mutable DOMMatrix object given an existing matrix or a DOMMatrixInit dictionary which provides the values for its properties.

Usage notes

The matrix defined by the DOMMatrix interface is comprised of four rows of four columns each. While it's beyond the scope of this article to explain the mathematics involved, this 4×4 size is enough to describe any transformation you might apply to either 2D or 3D geometries.

Here are the positions of the 16 elements (m_11 through m_44) which comprise the 4×4 abstract matrix:

33Starting in Firefox 69, the first parameter (scale) is now optional with a default value of 1, per the specification. Previously it was required.

No

48

11

61

61

33Firefox for Android requires the first parameter (scale).

45

11

8.0

scaleSelf

61

79

33Firefox 69 introduced support for the modern six-parameter syntax for scaleSelf(). Previously, it only supported the older three-parameter syntax: scale(scaleX[, originX][, originY]]]).

No

48

11

61

61

33Firefox for Android only supports the older three-parameter syntax for scaleSelf(): scale(scaleX[, originX][, originY]]]), and not the six-parameter syntax.