/CSS

# matrix()

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

## Try it

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

a b c d

Are `<number>`s describing the linear transformation.

tx ty

Are `<number>`s describing the translation to apply.

Cartesian coordinates on ℝ^2 Homogeneous coordinates on ℝℙ^2 Cartesian coordinates on ℝ^3 Homogeneous coordinates on ℝℙ^3
$\left(\begin{array}{cc}a& c\\ b& d\end{array}\right)$ $\left(\begin{array}{ccc}a& c& \mathrm{tx}\\ b& d& \mathrm{ty}\\ 0& 0& 1\end{array}\right)$ $\left(\begin{array}{ccc}a& c& \mathrm{tx}\\ b& d& \mathrm{ty}\\ 0& 0& 1\end{array}\right)$ $\left(\begin{array}{cccc}a& c& 0& \mathrm{tx}\\ b& d& 0& \mathrm{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())`

## 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;
}
```

## Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
`matrix`
1
12
3.5
Before Firefox 16, the translation values of `matrix()` could be `<length>`s, in addition to the standard `<number>`.
9
10.5
3.1
2
18
4
11
3.2
1.0