Skip to main content
Syllabus
On this page

CSS 2D Transforms: translate, rotate, scale, skew and transform-origin

Badar KhalilUpdated September 30, 2026 4 min read

What are CSS 2D transforms?

CSS 2D transforms let you move, rotate, resize and skew an element in a flat, two-dimensional plane using the transform property. They do not change the document flow: the element's original space is still reserved, so neighbors do not move. That makes transforms ideal for animation, because the browser can often hand them to the GPU compositor without recalculating layout.

Focus keyword: CSS 2D transforms. Related trending keywords: CSS translate property, individual transform properties, transform-origin, CSS rotate scale, hardware accelerated transforms, center element with transform, hover zoom effect.

The 2D transform functions

  • translate(x, y), translateX(), translateY(): move the element. Percentages are relative to the element's own size, not its parent.
  • rotate(angle): rotate clockwise for positive values. Units: deg, rad, grad, turn (for example 0.25turn).
  • scale(x, y), scaleX(), scaleY(): resize. 1 is normal size, 2 doubles it and negative values flip it.
  • skew(x-angle, y-angle), skewX(), skewY(): slant the element.
  • matrix(a, b, c, d, tx, ty): all 2D transforms combined into one matrix. Rarely written by hand, but it is what the browser computes.

Combining transforms and the order rule

List multiple functions in one declaration, separated by spaces: transform: translateX(100px) rotate(45deg) scale(1.2);. Order matters. Functions apply right to left in terms of coordinate space: rotating first and then translating moves the element along the rotated axis, while translating first and then rotating moves it along the original axis. If an animation looks wrong, check the order.

Also remember that a second transform declaration replaces the first. To add to an existing transform you must repeat all functions, or use the individual properties below.

transform-origin

By default, transforms happen around the element's center (50% 50%). The transform-origin property changes the pivot point. For example, transform-origin: top left makes a rotation swing like a door hinge, and transform-origin: bottom center makes a scale grow upward from the base.

Individual transform properties: translate, rotate, scale

Modern CSS has separate translate, rotate and scale properties. They are applied in a fixed order (translate, then rotate, then scale, then the regular transform), and you can change or transition one of them without rewriting the others. This is very handy for hover states and keyframes. Example: .card:hover { scale: 1.05; } while another rule sets rotate: 3deg.

Centering with translate

A classic pattern for absolutely positioned elements is top: 50%; left: 50%; transform: translate(-50%, -50%);. Today, place-items: center on a grid parent or inset: 0; margin: auto is often simpler, but the translate technique is still common in legacy code and interviews.

Important behavior to remember

  • Transforms do not affect layout, only visual rendering. Scrolling area may still be affected by overflow.
  • A transformed element becomes a containing block for fixed-position descendants and creates a new stacking context.
  • Non-replaced inline elements (like a plain span) cannot be transformed. Use display: inline-block.
  • Scaling text can make it look blurry during animation. Prefer animating from a slightly larger size down, or use will-change sparingly.
  • Always make sure interactive targets stay large enough for touch after scaling or rotating.

Quick summary

Use CSS 2D transforms for movement, rotation, zoom and skew effects. Combine them carefully, set the right transform-origin, and prefer the individual properties when you need to animate parts separately.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Exercise: Create a hinged door rotationHTML

Make the .door rotate 35 degrees around its top-left corner when hovering the .frame. Use transform-origin and a 400ms transition. Do not use the transform shorthand on hover: use the individual rotate property instead.

Try it Yourself HTML
Output

Press Run to execute.

Show expected output
On hover the orange panel swings 35 degrees around its top-left corner like a door hinge.

This is a self-check — compare your result with the expected output above.

Was this page helpful?