concept

Perspective projection — CSS reference

Perspective divides projected coordinates by a homogeneous factor. For this simple front-facing plane at z less than distance d, scale is d/(d−z). At z=200px and d=400px the scale is two. This formula is not a general clipping algorithm.

Formal Syntax & Structure

css syntaxcss
transform: perspective(400px) translateZ(200px);

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>perspective-projection</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}#scene{position:relative;margin:0;width:300px;height:300px}#a{width:100px;height:60px;padding:0;transform-origin:0 0;background:rgb(0,100,0);color:white}#b{width:100px;height:20px;background:rgb(40,80,180)}#a{transform:perspective(400px) translateZ(200px)}</style><body><main id="scene"><div id="a">A</div><div id="b">B</div></main></body></html>
CSS Reference