docs.rodeo

MDN Web Docs mirror

matrix()

{{CSSRef}} 

The matrix() CSS function defines a homogeneous 2D transformation matrix. Its result is a {{cssxref("<transform-function>")}}  data type.

{{EmbedInteractiveExample("pages/css/function-matrix.html")}} 

Note: matrix(a, b, c, d, tx, ty) is a shorthand for matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1).

Syntax

The matrix() function is specified with six values. The constant values are implied and not passed as parameters; the other parameters are described in the column-major order.

matrix(a, b, c, d, tx, ty)

Values

Cartesian coordinates on ℝ^2 Homogeneous coordinates on ℝℙ^2 Cartesian coordinates on ℝ^3 Homogeneous coordinates on ℝℙ^3
(acbd)\begin{pmatrix} a & c \\ b & d \end{pmatrix} (actxbdty001)\left( \begin{array}{ccc} a & c & tx \\ b & d & ty \\ 0 & 0 & 1 \\ \end{array} \right) (actxbdty001)\left( \begin{array}{ccc} a & c & tx \\ b & d & ty \\ 0 & 0 & 1 \\ \end{array} \right) (ac0txbd0ty00100001)\left( \begin{array}{cccc} a & c & 0 & tx \\ b & d & 0 & ty \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{array} \right)
[a b c d tx ty]

The values represent the following functions: matrix(scaleX(), skewY(), skewX(), scaleY(), translateX(), translateY()).

Formal syntax

{{CSSSyntax}} 

Examples

HTML

<div>Normal</div>
<div class="changed">Changed</div>

CSS

div {
  width: 80px;
  height: 80px;
  background-color: skyblue;
}

.changed {
  transform: matrix(1, 2, -1, 1, 80, 80);
  background-color: pink;
}

Result

{{EmbedLiveSample("Examples", 350, 350)}} 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN