CKTIS / CSS
perspective(): depth in a transform list
Project a transformed element in three dimensions and see why the order of transforms matters.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
transform: perspective(200px) translateZ(100px);perspective() adds a perspective projection to the transform list of one element. Its length represents the viewing distance: a point translated towards the viewer can appear larger, while a point farther away can appear smaller. With distance d and depth z below d, the scale is d / (d - z). Merely adding perspective() to a flat element at z = 0 does not enlarge it.
The function is not the perspective property placed on a parent to give its transformed children a shared perspective. Transform order matters. The distance cannot be negative or a percentage; values below 1px are clamped to 1px for rendering. Do not apply the scale formula across the viewing plane: geometry at or beyond it is subject to clipping.
The example projects an 80×40 box with perspective(200px) translateZ(100px), producing a measured 160×80 rectangle. Reversing the two functions gives 80×40. transform-origin: 0 0 makes the comparison easier to inspect. offsetWidth and offsetHeight remain 80 and 40: the visual transform does not resize the box used by normal layout.
Examples
const box=document.createElement('div');
box.style.cssText='position:fixed;left:0;top:0;width:80px;height:40px;transform-origin:0 0';
document.body.append(box);
const measure=value=>{box.style.transform=value;const r=box.getBoundingClientRect();return r.width.toFixed(2)+'x'+r.height.toFixed(2)};
const projected=measure('perspective(200px) translateZ(100px)');
const reversed=measure('translateZ(100px) perspective(200px)');
console.log('projected='+projected+'; reversed='+reversed+'; layout='+box.offsetWidth+'x'+box.offsetHeight+'; negative='+CSS.supports('transform','perspective(-1px)')+'; percent='+CSS.supports('transform','perspective(50%)'));Result
projected=160.00x80.00; reversed=80.00x40.00; layout=80x40; negative=false; percent=false
Measured in Chromium 157.0.8103.51. This checks the shown transform order and invalid distance forms, not every 3D stacking or clipping configuration.