DOMMatrix: scaleSelf() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Note: This feature is available in Web Workers.

The scaleSelf() method of the DOMMatrix interface is a mutable transformation method that modifies a matrix by applying a specified scaling factor, centered on the given origin, with a default origin of (0, 0), returning the scaled matrix.

To scale a matrix without mutating it, see DOMMatrixReadOnly.scale(), which creates a new scaled matrix while leaving the original unchanged.

Syntax

js
scaleSelf()
scaleSelf(scaleX)
scaleSelf(scaleX, scaleY)
scaleSelf(scaleX, scaleY, scaleZ)
scaleSelf(scaleX, scaleY, scaleZ, originX)
scaleSelf(scaleX, scaleY, scaleZ, originX, originY)
scaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ)

Parameters

scaleX Optional

A multiplier for the scale value on the x-axis. If not supplied, this defaults to 1.

scaleY Optional

A multiplier for the scale value on the y-axis. If not supplied, this defaults to the value of scaleX.

scaleZ Optional

A multiplier for the scale value on the z-axis. If this value is anything other than 1, the resulting matrix will be 3D.

originX Optional

An x-coordinate for the origin of the transformation. If no origin is supplied, this defaults to 0.

originY Optional

A y-coordinate for the origin of the transformation. If no origin is supplied, this defaults to 0.

originZ Optional

A z-coordinate for the origin of the transformation. If no origin is supplied, this defaults to 0. If this value is anything other than 0, the resulting matrix will be 3D.

Return value

Returns itself; a DOMMatrix.

If a scale is applied about the z-axis, the matrix will be a 4✕4 3D matrix.

Examples

This SVG contains two semi-opaque squares, one red and one blue, each positioned at the document origin:

html
<svg viewBox="0 0 50 50" height="200">
  <rect width="25" height="25" fill="#ff000099" />
  <rect id="transformed" width="25" height="25" fill="#0000ff99" />
</svg>

This JavaScript first creates a matrix, then scales the matrix to one that halves the width and doubles the height, using the scaleSelf() method.

The matrix is then applied to the blue square as a transform, changing its dimensions and position. The red square is left unchanged.

js
const matrix = new DOMMatrix();
matrix.scaleSelf(0.5, 2);

document
  .querySelector("#transformed")
  .setAttribute("transform", matrix.toString());

Specifications

Specification
Geometry Interfaces Module Level 1
# dom-dommatrix-scaleself

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
scaleSelf()
Chrome – Full support
Chrome 61 (Release date: 2017-09-05)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 33 (Release date: 2014-10-14)
footnote
footnote Firefox 69 introduced support for the modern six-parameter syntax for scaleSelf(). Previously, it only supported the older three-parameter syntax: scale(scaleX[, originX][, originY]]]).
Opera – Full support
Opera 48 (Release date: 2017-09-27)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 61 (Release date: 2017-09-05)
footnote Full support
Firefox for Android – Full support
Firefox for Android 33 (Release date: 2014-10-14)
footnote
footnote Firefox for Android 79 introduced support for the modern six-parameter syntax for scaleSelf(). Previously, it only supported the older three-parameter syntax: scale(scaleX[, originX][, originY]]]).
Opera Android – Full support
Opera Android 45 (Release date: 2018-02-15)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 8 (Release date: 2018-07-18)
footnote Full support
WebView Android – Full support
WebView Android 61 (Release date: 2017-09-05)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also