Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

rotateY(): turn around the vertical axis

Rotate a box in depth and distinguish its projected width from its layout width.

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

Syntax

transform: rotateY(60deg);

The function rotateY() rotates around the local Y axis; transform-origin sets the pivot. It accepts an angle such as 60deg, and unitless 0 is also allowed. In the usual CSS coordinates, positive X points right and positive Z points towards the viewer. A positive quarter-turn sends a point on the positive X axis towards negative Z; a negative quarter-turn sends it towards the viewer.

The rotation is already three-dimensional without perspective, but its projection can simply look narrower. Perspective supplies depth-dependent foreshortening. Nested faces may require transform-style: preserve-3d; backface-visibility controls whether a reversed face is painted. These are separate choices, not automatic effects of calling rotateY(). Transform order matters, and the transformed box does not make surrounding normal-flow content rearrange itself.

The example reads the actual transform matrix: a point 100 units to the right becomes 0,0,-100 after 90deg and 0,0,100 after -90deg. With no perspective, 60deg projects a 100px-wide box to 50px. Its layout width remains 100px. The rounded output avoids floating-point noise; the points describe local coordinates, not positions in the viewport.

Examples

const box=document.createElement('div');
box.style.cssText='position:absolute;left:200px;top:200px;width:100px;height:40px;transform-origin:0 0';
document.body.append(box);
const point=angle=>{box.style.transform='rotateY('+angle+'deg)';const matrix=new DOMMatrix(getComputedStyle(box).transform);const p=matrix.transformPoint(new DOMPoint(100,0,0));return [p.x,p.y,p.z].map(v=>Math.round(v)).join(',')};
console.log('positive='+point(90)+'; negative='+point(-90));
box.style.transform='rotateY(60deg)';
console.log('visual-width='+Math.round(box.getBoundingClientRect().width)+'; layout-width='+box.offsetWidth+'; perspective='+getComputedStyle(box).perspective);

Result

positive=0,0,-100; negative=0,0,100
visual-width=50; layout-width=100; perspective=none

The width comparison demonstrates projection without perspective. A different pivot or an additional perspective transform changes the geometry; the layout width is not the projected width.

Sources