CKTIS / CSS
matrix3d(): a homogeneous 3D transformation
Express a three-dimensional transform with sixteen coefficients in column-major order.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
transform: matrix3d(2,0,0,0, 0,3,0,0, 0,0,1,0, 10,20,30,1);matrix3d() supplies the sixteen coefficients of a 4 by 4 homogeneous transformation matrix. CSS lists them column by column, not row by row. For an ordinary affine transform, the thirteenth, fourteenth and fifteenth values hold the x, y and z translations. The diagonal can encode scale, while other coefficients can represent rotation, shear or perspective-related effects.
A nonzero z translation does not automatically make an object appear larger or smaller. Perspective has to be introduced by the transform or an appropriate perspective context. transform-origin and the surrounding 3D rendering context also affect the final result. A matrix that is effectively two-dimensional may be simplified by browser serialization; merely writing sixteen values does not guarantee a visible 3D effect.
The example scales a 40 by 30 pixel box by 2 and 3, then translates by 10,20,30 in a matrix with no perspective. DOMMatrix reports the three translation components and is2D as false because of the z component. The measured rendered box is still 80 by 90, without perspective enlargement, while its normal layout dimensions remain unchanged.
Examples
const value='matrix3d(2,0,0,0, 0,3,0,0, 0,0,1,0, 10,20,30,1)';
const element=document.createElement('div');element.style.cssText='position:fixed;left:0;top:0;width:40px;height:30px;transform-origin:0 0';element.style.transform=value;document.body.append(element);
const rect=element.getBoundingClientRect();const matrix=new DOMMatrix(getComputedStyle(element).transform);
console.log('translation='+matrix.m41+','+matrix.m42+','+matrix.m43+'; rendered='+rect.width+'x'+rect.height+'; is2D='+matrix.is2D+'; perspective='+getComputedStyle(element).perspective);Result
translation=10,20,30; rendered=80x90; is2D=false; perspective=none
The z value is present in the matrix even though the orthographic screen projection does not turn it into a size change.