CKTIS / CSS
rotate(): a two-dimensional turn whose order matters
Rotate around the chosen origin without confusing visual bounds with the element’s layout size.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
transform: rotate(90deg);The transform function rotate() takes an angle, or a unitless zero, and turns the element around transform-origin. In the usual CSS screen coordinates, x increases to the right and y downwards, so a positive quarter-turn sends a point on the positive x axis towards the positive y axis. The example checks this in both text directions. Do not confuse this function inside transform with the separate rotate property or the older three-argument SVG attribute syntax.
Order is significant: the matrix for the rightmost function acts on a local point first. A rotation followed by a translation in the written list therefore differs from a translation followed by a rotation. The origin also affects the final placement. Reading the computed transform matrix alone does not incorporate the extra translations around the separately specified origin; the example fixes that origin at zero and treats the matrix probe accordingly.
In Chromium 157, a positive 90-degree turn maps the test point to 0,10 for both ltr and rtl, while the negative turn gives 0,-10. Swapping the two-function lists changes the transformed origin from 0,10 to 10,0. The final 80-by-40 box retains those layout dimensions, but its axis-aligned visual bounds become 40 by 80. A transform changes rendering and can affect overflow; it does not rearrange surrounding normal-flow layout to fit the rotated rectangle.
Examples
const box = document.createElement('div');
box.style.cssText = 'width:80px;height:40px;transform-origin:0 0';
document.body.append(box);
function point(transform, x, y) {
box.style.transform = transform;
const p = new DOMMatrix(getComputedStyle(box).transform).transformPoint(new DOMPoint(x,y));
return [p.x,p.y].map(n => Number(n.toFixed(6))).join(',');
}
for (const direction of ['ltr','rtl']) {
box.style.direction = direction;
console.log(direction + ' +90:', point('rotate(90deg)',10,0));
}
console.log('-90:', point('rotate(-90deg)',10,0));
console.log('rotate then translate list:', point('rotate(90deg) translateX(10px)',0,0));
console.log('translate then rotate list:', point('translateX(10px) rotate(90deg)',0,0));
box.style.transform = 'rotate(90deg)';
console.log('layout:', box.offsetWidth, box.offsetHeight);
const bounds = box.getBoundingClientRect();
console.log('visual bounds:', Math.round(bounds.width), Math.round(bounds.height));
box.remove();Result
ltr +90: 0,10 rtl +90: 0,10 -90: 0,-10 rotate then translate list: 0,10 translate then rotate list: 10,0 layout: 80 40 visual bounds: 40 80
Point coordinates are obtained from the computed matrix and rounded to six decimals. Bounding-box dimensions are measured separately; no animation or screenshot-based orientation judgment is involved.