GL-Matrix Mat4 to CSS Matrix3D Converter
Convert gl-matrix mat4 arrays to CSS matrix3d() transform strings. Paste 16 float values, get GPU-accelerated CSS transforms instantly.
About
Moving DOM elements via position: absolute with top/left triggers browser repaints on every frame. The GPU never touches it. Applying transforms through matrix3d() offloads the entire computation to the compositor thread, eliminating layout thrashing and achieving 60 fps animations on constrained hardware. The gl-matrix library stores mat4 as a column-major 16-element Float32Array. CSS matrix3d() accepts the same 16 values in identical column-major order. The mapping is a direct pass-through, but manual transcription of 16 floating-point values invites off-by-one index errors that produce silent visual corruption rather than exceptions.
This tool parses raw mat4 output, validates all 16 components as finite IEEE 754 floats, and emits a copy-ready matrix3d() string. It also decomposes the matrix into translation (tx, ty, tz), scale factors, and renders the 4×4 grid so you can visually verify the structure before applying it. Note: decomposition assumes an affine transformation matrix. Non-affine projective matrices will report scale values that include shear components.
Formulas
The gl-matrix mat4 stores a 4×4 matrix in column-major layout as a flat array of 16 floats. The CSS matrix3d() function accepts exactly 16 comma-separated values in the same column-major order:
The 4×4 matrix in conventional mathematical notation maps to the flat array as:
Translation is extracted from indices 12, 13, 14:
Scale factors are derived from the magnitudes of the first three column vectors:
Where m[i] denotes the value at flat array index i in column-major order.
Reference Data
| Index | Column | Row | Role | CSS matrix3d() Position | Common Use |
|---|---|---|---|---|---|
| 0 | 0 | 0 | m00 | 1st arg | Scale X / Rotate |
| 1 | 0 | 1 | m01 | 2nd arg | Rotate / Shear |
| 2 | 0 | 2 | m02 | 3rd arg | Rotate (3D) |
| 3 | 0 | 3 | m03 | 4th arg | Perspective X |
| 4 | 1 | 0 | m10 | 5th arg | Rotate / Shear |
| 5 | 1 | 1 | m11 | 6th arg | Scale Y / Rotate |
| 6 | 1 | 2 | m12 | 7th arg | Rotate (3D) |
| 7 | 1 | 3 | m13 | 8th arg | Perspective Y |
| 8 | 2 | 0 | m20 | 9th arg | Rotate (3D) |
| 9 | 2 | 1 | m21 | 10th arg | Rotate (3D) |
| 10 | 2 | 2 | m22 | 11th arg | Scale Z / Rotate |
| 11 | 2 | 3 | m23 | 12th arg | Perspective Z |
| 12 | 3 | 0 | m30 | 13th arg | Translate X |
| 13 | 3 | 1 | m31 | 14th arg | Translate Y |
| 14 | 3 | 2 | m32 | 15th arg | Translate Z |
| 15 | 3 | 3 | m33 | 16th arg | Homogeneous W (usually 1) |