The DOMMatrix
interface represents 4x4 matrices, suitable for 2D and 3D operations including rotation and translation. It is a mutable version of the DOMMatrixReadOnly
interface.
This interface should be available inside web workers, though some implementations don't allow it yet.
Constructor
DOMMatrix()
 Creates and returns a new
DOMMatrix
object.
Properties
This interface inherits properties from DOMMatrixReadOnly
, though some of these properties are altered to be mutable.
is2D
Read only A Boolean flag whose value is
true
if the matrix was initialized as a 2D matrix; iffalse
, the matrix is 3D. isIdentity
Read only A Boolean whose value is
true
if the matrix is the identity matrix. The identity matrix is one in which every value is 0 except those on the main diagonal from topleft to bottomright corner (in other words, where the offsets in each direction are equal). m11
,m12
,m13
,m14
,m21
,m22
,m23
,m24
,m31
,m32
,m33
,m34
,m41
,m42
,m43
,m44
 Doubleprecision floatingpoint values representing each component of a 4x4 matrix, where
m11
throughm14
are the first column,m21
throughm24
are the second column, and so forth. a
,b
,c
,d
,e
,f

Doubleprecision floatingpoint values representing the components of a 4x4 matrix which are required in order to perform 2D rotations and translations. These are aliases for specific components of a 4x4 matrix, as shown below.
2D
3D equivalent
a
m11
b
m12
c
m21
d
m22
e
m41
f
m42
Methods
This interface includes the following methods, as well as the methods it inherits from DOMMatrixReadOnly
.
DOMMatrix.invertSelf()
 Modifies the matrix by inverting it. If the matrix can't be inverted, its components are all set to
NaN
, andis2D
returnsfalse
. DOMMatrix.multiplySelf()
 Modifies the matrix by postmultiplying it with the specified
DOMMatrix
; this is equivalent to the dot productA⋅B
, where matrix A is the source matrix and B is the matrix given as an input to the method. Also returns itself. DOMMatrix.preMultiplySelf()
 Modifies the matrix by premultiplying it with the specified
DOMMatrix
; this is equivalent to the dot productB⋅A
, where matrix A is the source matrix and B is the matrix given as an input to the method. Also returns itself. DOMMatrix.translateSelf()
 Modifies the matrix by applying the specified vector. Also returns itself. The default vector is [0, 0, 0].
DOMMatrix.scaleNonUniformSelf()
 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). Also returns itself.
DOMMatrix.scaleSelf()
 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). Also returns itself.
DOMMatrix.scale3dSelf()
 Modifies the matrix by applying the specified scaling factor to all three axes, centered on the given origin. Returns itself.
DOMMatrix.rotateSelf()
 Modifies the matrix by rotating itself around each axis by the specified number of degrees. Also returns itself.
DOMMatrix.rotateAxisAngleSelf()
 Modifies the matrix by rotating it by the specified angle around the given vector. Also returns itself.
DOMMatrix.rotateFromVectorSelf()
 Modifies the matrix by rotating it by the angle between the specified vector and (1, 0). Also returns itself.
DOMMatrix.setMatrixValue()
 Replaces the contents of the matrix with the matrix described by the specified transform or transforms. Returns itself as well.
DOMMatrix.skewXSelf()
 Modifies the matrix by applying the specified skew transformation along the Xaxis. Also returns itself.
DOMMatrix.skewYSelf()
 Modifies the matrix by applying the specified skew transformation along the Yaxis. Also returns itself.
Static methods
This interface inherits methods from DOMMatrixReadOnly
.
fromFloat32Array()
 Creates a new mutable
DOMMatrix
object given an array of singleprecision (32bit) floatingpoint 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, aTypeError
exception is thrown. fromFloat64Array()
 Creates a new mutable
DOMMatrix
object given an array of doubleprecision (64bit) floatingpoint 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, aTypeError
exception is thrown. fromMatrix()
 Creates a new mutable
DOMMatrix
object given an existing matrix or aDOMMatrixInit
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 4x4 size is enough to describe any transformation you might apply to either 2D or 3D geometries.
The DOMMatrix
interface is designed with the intent that it will be used for all matrices within markup, supplanting the SVGMatrix
and CSSMatrix
interfaces.
Specifications
Specification  Status  Comment 

Geometry Interfaces Module Level 1 The definition of 'DOMMatrix' in that specification. 
Candidate Recommendation  Initial definition 
Browser compatibility
Desktop  Mobile  

DOMMatrix  Chrome Full support 61  Edge No support No  Firefox Full support 33  IE No support No  Opera Full support 48  Safari Full support 11  WebView Android Full support 61  Chrome Android Full support 61  Firefox Android Full support 33  Opera Android Full support 45  Safari iOS Full support 11  Samsung Internet Android ? 
DOMMatrix() constructor  Chrome Full support 61  Edge No support No  Firefox Full support 33  IE No support No  Opera Full support 48  Safari Full support 11  WebView Android Full support 61  Chrome Android Full support 61  Firefox Android Full support 33  Opera Android Full support 45  Safari iOS Full support 11  Samsung Internet Android ? 
Available in workers  Chrome Full support 61  Edge No support No  Firefox No support No  IE No support No  Opera Full support 48  Safari Full support 11  WebView Android Full support 61  Chrome Android Full support 61  Firefox Android No support No  Opera Android Full support 45  Safari iOS Full support 11  Samsung Internet Android ? 
Legend
 Full support
 Full support
 No support
 No support
 Compatibility unknown
 Compatibility unknown
See also
 Its nonmodifiable part,
DOMMatrixReadOnly
SVGMatrix
, the SVG matrix intended to be superseded byDOMMatrix