matrix()

Baseline Widely available

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

matrix()CSS関数で、二次元同次変換行列を定義します。結果は <transform-function> データ型になります。

試してみましょう

メモ: matrix(a, b, c, d, tx, ty)matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1) の短縮形です。

構文

matrix() 関数は 6 つの値で指定されます。定数は内蔵されていて引数としては渡されず、その他の引数は列優先の順で記述されます。

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

a b c d

<number> で、線形変換を記述します。

tx ty

<number> で、適用する変換を記述します。

直交座標系 (ℝ^2) 同次座標系 (ℝℙ^2) 直交座標系 (ℝ^3) 同次座標系 (ℝℙ^3)
(a c b d) (a c tx b d ty 0 0 1) (a c tx b d ty 0 0 1) (a c 0 tx b d 0 ty 0 0 1 0 0 0 0 1)
[a b c d tx ty]

値は次の関数を表します。 matrix(scaleX(), skewY(), skewX(), scaleY(), translateX(), translateY())

HTML

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

CSS

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

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

結果

仕様書

Specification
CSS Transforms Module Level 1
# funcdef-transform-matrix

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
matrix()

Legend

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

Full support
Full support
See implementation notes.

関連情報