CKTIS / CSS
rotate3d(): an axis direction and one rotation angle
Normalize a three-component axis, handle the zero vector, and keep the order of spatial rotations explicit.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
transform: rotate3d(0, 0, 1, 90deg);The first three arguments of rotate3d() are unitless numbers describing the axis direction; they are not three angles or translations. The fourth argument is one angle, or a unitless zero. The browser normalizes a nonzero axis, so multiplying all its components by the same positive factor does not change the turn. A vector that cannot be normalized, such as 0,0,0, makes this rotation have no effect rather than invalidating the whole transform list.
A positive turn is clockwise when viewed from the positive end of the axis towards the origin, following CSS’s coordinate convention. transform-origin determines the point through which the axis passes. Rotations about different axes generally do not commute: swapping them can change the result. A rotation needs no perspective to be computed, while perspective changes its projection; preserving a shared three-dimensional space for descendants is a separate concern.
The example uses computed matrices, not a visual guess about depth. Axes 0,0,1 and 0,0,5 both send the test point to 0,10,0, while the zero axis leaves it at 10,0,0. Applying the two written axis rotations in the opposite order produces 1,0,0 or 0,-1,0 for the same input point. A length such as 1px in the axis is rejected because axis components are numbers. The calculation checks matrix behavior, not perspective painting or interactions between nested elements.
Examples
const box = document.createElement('div');
document.body.append(box);
function point(transform, x, y, z) {
box.style.transform = transform;
const p = new DOMMatrix(getComputedStyle(box).transform).transformPoint(new DOMPoint(x,y,z));
return [p.x,p.y,p.z].map(n => Number(n.toFixed(6))).join(',');
}
console.log('unit z axis:', point('rotate3d(0,0,1,90deg)',10,0,0));
console.log('scaled z axis:', point('rotate3d(0,0,5,90deg)',10,0,0));
console.log('zero axis:', point('rotate3d(0,0,0,90deg)',10,0,0));
console.log('X then Y list:', point('rotate3d(1,0,0,90deg) rotate3d(0,1,0,90deg)',0,0,1));
console.log('Y then X list:', point('rotate3d(0,1,0,90deg) rotate3d(1,0,0,90deg)',0,0,1));
console.log('length in axis:', CSS.supports('transform', 'rotate3d(1px,0,0,90deg)'));
box.remove();Result
unit z axis: 0,10,0 scaled z axis: 0,10,0 zero axis: 10,0,0 X then Y list: 1,0,0 Y then X list: 0,-1,0 length in axis: false
The browser executes both rotation orders on real computed matrices. Rounded coordinates remove floating-point display noise; the zero-axis case is a no-op rotation, not an error recovery fallback.