CKTIS / CSS
rotateZ(): rotate in the plane of the screen
Use the Z axis for planar rotation while keeping the original layout box.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
transform: rotateZ(90deg);The function rotateZ() rotates around the local Z axis, which points out of the screen in the usual CSS coordinate system. Its angle produces the same geometric transformation as rotate(). With X pointing right and Y down, a positive 90deg turns a rightward point downward; -90deg turns it upward. The pivot comes from transform-origin rather than from the top-left corner by necessity.
A rotation changes the painted shape and its viewport bounding rectangle, not the dimensions used by normal flow. Neighbouring elements can therefore overlap it. Transform functions compose in order: adding a translation before or after a rotation can move the box differently. Do not infer layout dimensions from the enclosing rectangle of a rotated element, and do not expect rotateZ() to create perspective.
The example fixes the pivot at the top-left of an 80px by 20px box positioned at 200px,200px. At 90deg its bounding rectangle is 180,200,20,80; at -90deg it is 200,120,20,80. The local point 10,0 moves to 0,10 or 0,-10. Finally the computed matrices for rotate(90deg) and rotateZ(90deg) match, while the layout dimensions stay 80x20.
Examples
const box=document.createElement('div');
box.style.cssText='position:absolute;left:200px;top:200px;width:80px;height:20px;transform-origin:0 0';
document.body.append(box);
for(const angle of [90,-90]){box.style.transform='rotateZ('+angle+'deg)';const matrix=new DOMMatrix(getComputedStyle(box).transform);const p=matrix.transformPoint(new DOMPoint(10,0));const r=box.getBoundingClientRect();console.log(angle+': point='+[p.x,p.y].map(v=>Math.round(v)).join(',')+'; bounds='+[r.x,r.y,r.width,r.height].map(v=>Math.round(v)).join(','))}
box.style.transform='rotate(90deg)';const a=getComputedStyle(box).transform;
box.style.transform='rotateZ(90deg)';
console.log('same-matrix='+String(a===getComputedStyle(box).transform)+'; layout='+box.offsetWidth+'x'+box.offsetHeight);Result
90: point=0,10; bounds=180,200,20,80 -90: point=0,-10; bounds=200,120,20,80 same-matrix=true; layout=80x20
The positive and negative rotations move the bounding rectangle in different directions. The unchanged layout dimensions are measured separately from that rectangle.