design hubs
On this page
Properties
2 min read

Transform

Translate, rotate, skew, and their 3D equivalents are the primary tools for spatial animation. Understanding the coordinate system prevents the most common mistakes.

transform is the most powerful animation property in CSS. It moves, rotates, scales, and skews elements without touching layout — and it is the foundation of almost every spatial animation in a well-built interface.

The transform coordinate system

Transforms operate in the element’s local coordinate system, not the document’s. translateX(100px) moves an element 100px in its own horizontal axis — which may or may not align with the page’s horizontal axis if the element has been rotated. This becomes important when combining transforms: the order of transform functions matters because each is applied in sequence, and later transforms operate in the coordinate space left by earlier ones.

Transform origin

Every transform operates around a point: the transform origin. The default origin is the centre of the element. transform-origin: top left changes it to the top-left corner — a scale or rotation now pivots from that point. This is critical for animations where the element should grow from a specific edge (a tooltip expanding from its trigger) or rotate around a hinge point (a door opening from its left edge).

Translate

translate(x, y) or translateX() / translateY() moves an element without affecting layout. Use percentage values for relative movement — translateX(-100%) moves an element its own full width to the left, regardless of its actual pixel size. This makes it perfect for slide-in and slide-out animations that must work across different element sizes.

Rotate

rotate(deg) rotates an element around its transform origin. Small rotations (2–5 degrees) create subtle tilt effects for emphasis. Larger rotations (180 degrees) are used for flipping icons — a chevron that rotates to indicate an accordion opening, for example. Always specify the direction deliberately: positive values rotate clockwise.

3D transforms and perspective

translateZ(), rotateX(), and rotateY() operate in three dimensions, but require a perspective value on a parent element to render correctly. 3D transforms are used sparingly in UI — a card flip, a cube menu — because they add visual complexity that most interfaces do not benefit from. When you do use them, set perspective on the parent (not the element itself) and be consistent across the group.

The takeaway

Use translate for all spatial movement — never animate top, left, right, or bottom. Set transform-origin intentionally for any animation where the pivot point matters. Combine transforms using the shorthand transform: translateX() rotate() scale() and be aware that order affects the result.

Practice

0 / 3

Keyboard shortcuts

Show shortcuts
?
Search
CtrlK
Previous article
Next article
Close
Esc