Skip to content
Velloreth
Web Development 7 min read

CSS Transforms: Translate, Rotate, Scale and Skew

CSS transforms move, rotate, scale and skew elements without affecting layout. Learn the functions, the origin, 3D, and performance.

By

What transforms do

A transform changes how an element is rendered without affecting the layout of surrounding elements.

.card {
  transform: translateY(-4px);
}

The card moves up 4px visually, but the space it occupies in the layout is unchanged. Nothing else reflows.

This is what makes transforms the right tool for animation: they are composited, so the browser does not recalculate layout or repaint.

The core functions

translate

Moves the element.

transform: translateX(20px);
transform: translateY(-10px);
transform: translate(20px, -10px);
transform: translate(50%, 0); /* percentage of the element's own size */

The percentage is relative to the element’s own dimensions, which is why translate(-50%, -50%) is the classic centering trick.

.center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

rotate

Rotates the element.

transform: rotate(45deg);
transform: rotate(-90deg);
transform: rotate(0.25turn); /* 90deg */

scale

Resizes the element.

transform: scale(1.5);      /* both axes */
transform: scale(1.5, 0.5); /* x and y separately */
transform: scaleX(2);
transform: scaleY(0.5);

scale does not affect layout, so a scaled element can overlap its neighbours. That is usually the intent for hover effects.

skew

Slants the element.

transform: skewX(10deg);
transform: skewY(5deg);
transform: skew(10deg, 5deg);

Skew is used for decorative effects and for isometric-style layouts. It distorts text, so apply it to a container and counter-skew the content if needed.

Combining transforms

Multiple functions compose in the order written.

transform: translateX(50px) rotate(45deg);

This moves the element 50px right, then rotates it 45° around its (moved) centre.

transform: rotate(45deg) translateX(50px);

This rotates first, then moves 50px along the rotated x-axis — which is a diagonal direction.

Order matters. The two produce different results.

The mental model: each function operates in the coordinate system left by the previous one.

transform-origin

Sets the pivot point. Defaults to the element’s centre.

transform-origin: center;      /* default: 50% 50% */
transform-origin: top left;
transform-origin: bottom right;
transform-origin: 0 0;
transform-origin: 50% 100%;

A rotation around the top-left corner:

.door {
  transform-origin: left center;
  transform: rotateY(-30deg);
}

The origin matters most for rotation and scale. A scale from the top-left grows down and right; a scale from the centre grows in all directions.

3D transforms

perspective

Gives depth. Set it on the parent.

.scene {
  perspective: 1000px;
}

.card {
  transform: rotateY(45deg);
}

Without perspective, a rotateY looks like a horizontal squash. With it, the element appears to recede into the screen.

Smaller values give a more dramatic effect; larger values are subtler. 800–1200px is a reasonable range.

rotateX, rotateY, rotateZ

transform: rotateX(45deg); /* tilt forward/back */
transform: rotateY(45deg); /* turn left/right */
transform: rotateZ(45deg); /* same as rotate() */

translate3d and translateZ

transform: translate3d(10px, 20px, 30px);
transform: translateZ(50px); /* toward the viewer */

translateZ with a positive value brings the element closer, making it appear larger.

transform-style

Lets children share the parent’s 3D space.

.card {
  transform-style: preserve-3d;
}

.card .front,
.card .back {
  position: absolute;
  backface-visibility: hidden;
}

.card .back {
  transform: rotateY(180deg);
}

This is the basis of a flip card.

backface-visibility

transform: backface-visibility: hidden;

Hides the element when it faces away, which is what makes a flip card work.

Common patterns

Hover lift

.card {
  transition: transform 0.2s ease-out;
}

.card:hover {
  transform: translateY(-4px);
}

Hover scale

.avatar {
  transition: transform 0.2s ease-out;
}

.avatar:hover {
  transform: scale(1.1);
}

Flip card

.flip-card {
  perspective: 1000px;
}

.flip-card-inner {
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s;
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.flip-card-back {
  transform: rotateY(180deg);
}

Centering

.center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Isometric grid

.isometric {
  transform: rotateX(60deg) rotateZ(45deg);
}

Performance

Transforms are composited, which makes them the fastest properties to animate.

/* Fast: composited */
@keyframes slide {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
/* Slow: triggers layout */
@keyframes slide {
  from { left: -100%; }
  to   { left: 0; }
}

The rule: use transform instead of left, top, width, height, or margin for anything that moves or resizes.

will-change

.card {
  will-change: transform;
}

Hints that the element will animate, so the browser can promote it to its own layer. Use sparingly — each promoted layer consumes memory.

Creating a stacking context

A transform creates a new stacking context, which affects z-index and position: fixed descendants.

.parent {
  transform: translateZ(0); /* creates a stacking context */
}

This is a common source of confusion: a position: fixed child inside a transformed parent is positioned relative to the parent, not the viewport.

Gotchas

Order matters. translate then rotate differs from rotate then translate.

Transforms do not affect layout. A scaled element can overlap neighbours, and the original space is preserved.

Percentage translate is relative to the element, not the parent.

Transforms create a stacking context, which changes how z-index and position: fixed behave.

Text can become blurry when scaled, because the browser rasterises at the original size. Animating scale from 1 to 1.1 is usually fine; scaling to 3× may look soft.

transform overrides transform. Two rules setting transform do not combine; the later one wins. Use a single declaration with multiple functions.

Transforms and layout

A transform does not change the element’s box in the layout. The original space is preserved, and the transformed element is drawn on top.

.card {
  transform: scale(1.2);
}

The card appears 20% larger, but the space it occupies in the flow is unchanged. Neighbouring elements do not move, and the enlarged card may overlap them.

This is usually what you want for hover effects, because the layout does not jump. It is a problem when you want the layout to respond to the size change — for that, you need to change width or height, which triggers layout.

The distinction matters for animation. A scale animation is composited and smooth. A width animation recalculates layout on every frame and is much slower.

Transforms and accessibility

Two accessibility considerations apply to transforms.

Motion. A large transform animation can cause discomfort. Respect the preference:

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
  .card:hover {
    transform: none;
  }
}

Text scaling. A scale transform scales the rendered text, but it does not change the font size the browser reports. A user who zooms the page gets a different result from a user who increases the default font size, because the transform is applied after layout.

For text that should genuinely be larger, change font-size rather than applying a transform.

Practical guidance

  • Use transform for movement and resizing, not left or width.
  • Remember the order matters when combining functions.
  • Set transform-origin when rotating or scaling from a specific point.
  • Use perspective on the parent for 3D effects.
  • Use translate(-50%, -50%) for centering.
  • Add will-change: transform sparingly for frequently animated elements.
  • Watch for stacking context changes with position: fixed.
  • Combine functions in one declaration, since transform does not merge.

For the related guides, see css-animations-basics and css-grid-complete-guide. For the broader context, css-specificity-explained and improve-inp-core-web-vitals-static-site.

Quotable summary

CSS transforms change how an element is rendered without affecting the layout of surrounding elements, which is what makes them the right tool for animation. The four core functions are translate, rotate, scale, and skew, and they compose in the order written, so translate then rotate differs from rotate then translate. transform-origin sets the pivot point and defaults to the element’s centre. Transforms are composited, so they are the fastest properties to animate, and they should replace left, top, width, and height for anything that moves or resizes. A transform also creates a stacking context, which changes how z-index and position: fixed behave in descendants.

Frequently asked questions

What does a CSS transform do?
It changes how an element is drawn — moving, rotating, scaling, or skewing it — without affecting the layout of other elements. The element's original space is preserved.
What is the difference between translate and position?
translate moves the element visually without affecting layout, and it is composited so it animates smoothly. Changing position or left/top triggers layout and is much slower.
What is transform-origin?
It sets the point around which the transform is applied, defaulting to the element's centre (50% 50%). Setting it to top left makes a rotation pivot on the top-left corner.
Does the order of transform functions matter?
Yes. Transforms are applied left to right, and each one operates in the coordinate system left by the previous. translate(50px) rotate(45deg) differs from rotate(45deg) translate(50px).
What is the difference between scale and zoom?
scale is a transform, so it does not affect layout and is composited. zoom changes the layout size, is not standardised consistently, and is not composited.
How do I do 3D transforms?
Use translate3d, rotateX, rotateY, and perspective. perspective on the parent gives depth, and transform-style: preserve-3d lets children share the 3D space.