Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scaleZ(): depth scaling becomes visible in composition

Scale depth rather than width or height, and see why transform order matters with perspective.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

transform: perspective(240px) scaleZ(2) translateZ(30px);

scaleZ(s) applies the factors (1,1,s). It scales the Z coordinate, not the box’s thickness: CSS elements are flat surfaces. An unrotated box on z=0 therefore keeps its visible width and height under scaleZ(2) alone. The argument is a number or percentage factor, not a length such as 2px.

Depth scaling matters once another transform gives points a nonzero Z coordinate. Transform lists compose matrices in written order; for a point, the rightmost function acts first. Thus scaleZ(2) translateZ(30px) places the original plane at z=60, whereas translateZ(30px) scaleZ(2) places it at z=30. Perspective then makes that depth difference visible.

In the example the plain 40×30px box stays 40×30 and its matrix has m33=2. With perspective(240px), the first ordering produces a width of 53.33px and the second 45.71px, rounded to two decimals. The layout remains 40×30. These results use origin 0 0; they do not describe a universal width for every transformed scene.

Examples

const box=document.createElement('div');
box.style.cssText='position:fixed;left:60px;top:60px;width:40px;height:30px;transform-origin:0 0;transform:scaleZ(2)';
document.body.append(box);
const plain=box.getBoundingClientRect();
const depth=new DOMMatrix(getComputedStyle(box).transform).m33;
const measure=value=>{box.style.transform=value;const m=new DOMMatrix(getComputedStyle(box).transform);return {width:box.getBoundingClientRect().width.toFixed(2),z:m.m43}};
const first=measure('perspective(240px) scaleZ(2) translateZ(30px)');
const second=measure('perspective(240px) translateZ(30px) scaleZ(2)');
console.log('plain='+plain.width+'x'+plain.height+'; m33='+depth+'; scale-then-translate='+first.width+','+first.z+'; translate-then-scale='+second.width+','+second.z+'; layout='+box.offsetWidth+'x'+box.offsetHeight+'; length='+CSS.supports('transform','scaleZ(2px)'));

Result

plain=40x30; m33=2; scale-then-translate=53.33,60; translate-then-scale=45.71,30; layout=40x30; length=false

The output labels name the written function order, not the chronological application to a point. The m43 values 60 and 30 expose the depth difference before perspective division.

Sources