# CSS transform: translate, rotate, scale and transform-origin

> How CSS transform works: translate, rotate, scale and skew, the individual translate/rotate/scale properties, why order matters, transform-origin, 3D transforms, and smooth animations.

Author: [Marko Denic](https://markodenic.com/) | Published: 2026-11-04 | Updated: 2026-11-04 | Topics: CSS, Tutorial, Web Development | Canonical: https://markodenic.com/css-transform/

![CSS transform: translate, rotate, scale and transform-origin](https://markodenic.com/wp-content/uploads/2026/11/og-css-transform.png)

The `transform` property moves, rotates, scales or skews an element **visually**, without changing the layout around it. The element’s original space stays reserved, and nothing else on the page moves.

That’s what makes transforms ideal for animations and hover effects: they’re cheap for the browser to draw, and they never cause the page to reflow.

### Demo:

```html
<div class="tf-demo">
  <div class="tf-demo__box tf-demo__translate">translate</div>
  <div class="tf-demo__box tf-demo__rotate">rotate</div>
  <div class="tf-demo__box tf-demo__scale">scale</div>
  <div class="tf-demo__box tf-demo__skew">skew</div>
  <div class="tf-demo__box tf-demo__flip">rotateY</div>
</div>
```

```css
.tf-demo {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 16px;
  padding: 24px;
  border-radius: 16px;
  background: #f1f5f9;
  font: 600 14px/1 ui-monospace, monospace;
  perspective: 600px; /* for the 3D flip */
}

.tf-demo__box {
  display: grid;
  place-items: center;
  height: 90px;
  border-radius: 12px;
  background: #1d4ed8;
  color: #fff;
  cursor: pointer;
  transition: transform 0.4s ease;
}

/* Hover each box */
.tf-demo__translate:hover { transform: translateY(-12px); }
.tf-demo__rotate:hover    { transform: rotate(15deg); }
.tf-demo__scale:hover     { transform: scale(1.15); }
.tf-demo__skew:hover      { transform: skewX(-12deg); }
.tf-demo__flip:hover      { transform: rotateY(180deg); }
```

[See the live demo](https://markodenic.com/css-transform/#demo)

Hover (or tap) each box to see its transform.

## The transform functions

### translate(): move

Moves the element along the X and Y axes. Percentages are relative to the element’s **own** size, which is what makes `translate(-50%, -50%)` the classic trick for centering an absolutely positioned element (see [position absolute vs relative](https://markodenic.com/position-absolute-vs-relative/)).

```css
.a { transform: translateX(20px); }
.b { transform: translateY(-10px); }
.c { transform: translate(20px, -10px); }

/* Center inside a positioned parent */
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
```

### rotate(): turn

Rotates clockwise for positive values. Units: `deg`, `turn`, `rad`. A square rotated 45° and half hidden is one way to draw a [triangle](https://markodenic.com/css-triangle/), often used for speech-bubble arrows.

```css
.a { transform: rotate(45deg); }
.b { transform: rotate(-0.25turn); } /* 90° counterclockwise */
```

### scale(): resize

`1` is the normal size, `2` double, `0.5` half. A negative value mirrors the element: `scaleX(-1)` flips it horizontally.

```css
.a { transform: scale(1.1); }       /* 10% bigger */
.b { transform: scale(2, 0.5); }    /* wider and flatter */
.c { transform: scaleX(-1); }       /* mirror */
```

### skew(): slant

Tilts the element along an axis. Useful for slanted section backgrounds and “parallelogram” buttons.

```css
.ribbon { transform: skewX(-12deg); }
```

## Combining transforms

### Order matters

Read the functions from left to right: each one moves, turns or resizes the element’s coordinate system for the functions after it. So rotating first and then moving goes along the *rotated* axis, while moving first and then rotating doesn’t.

```css
/* Rotates, then moves 100px along the rotated axis: ends up down-right */
.a { transform: rotate(45deg) translateX(100px); }

/* Moves 100px right, then rotates in place: ends up to the right */
.b { transform: translateX(100px) rotate(45deg); }
```

### Individual properties: translate, rotate, scale

Modern CSS has separate `translate`, `rotate` and `scale` properties. You can change one without repeating the others, and animate them independently. They’re applied in a fixed order: translate, then rotate, then scale.

```css
.card {
  translate: 0 0;
  rotate: -2deg;
  transition: translate 0.2s, scale 0.2s;
}

.card:hover {
  translate: 0 -6px;  /* the rotation stays */
  scale: 1.03;
}
```

### transform-origin

The point the element rotates and scales around. The default is the center (`50% 50%`). Change it to rotate a door from its hinge, or grow an underline from the left, like the [animated underline](https://markodenic.com/css-before-after/) example.

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

.underline::after {
  transform-origin: left;
  transform: scaleX(0);
}
```

## 3D transforms

### Perspective and rotateY

Add `perspective` to the parent to give 3D transforms depth: a smaller value means a stronger effect. `rotateX` and `rotateY` flip elements around the horizontal and vertical axes. For card flips, hide the back face.

```css
.scene {
  perspective: 800px;
}

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

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

.card__front,
.card__back {
  backface-visibility: hidden;
}

.card__back {
  transform: rotateY(180deg);
}
```

## Good to know

- **Transforms don’t work on inline elements** like a plain `<span>` or `<a>`. Give them `display: inline-block`.
- **Animate transform and opacity**. They can run on the GPU without recalculating layout, so they stay smooth where animating `top`, `left` or `width` stutters. That’s how the [hamburger menu](https://markodenic.com/css-hamburger-menu/) morphs into an X. Pick the [easing](https://markodenic.com/ease-in-vs-ease-out/) to match the motion: ease-out for things entering, ease-in for things leaving.
- **A transform creates a containing block.** `position: fixed` children of a transformed element are positioned relative to it, not to the viewport.
- **It creates a stacking context**, which can change how `z-index` behaves for the element’s children. That’s a common reason a `z-index` stops working; see how a [stacking context](https://markodenic.com/css-z-index/) works.

## FAQ

### Does transform affect layout?

No. The element is drawn moved, rotated or scaled, but its original box keeps its place, and other elements don’t move.

### How do I apply multiple transforms?

List them in one property, separated by spaces: `transform: translateX(10px) rotate(5deg) scale(1.1);`. A second `transform` declaration replaces the first one; it doesn’t add to it.

### Why isn’t my transform working?

The element is probably inline (use `inline-block`), a later rule overwrites the `transform`, or two functions cancel each other out in that order.

### What’s the difference between translate and position relative?

Both move an element without affecting others. `translate` is better for animation (no layout work) and its percentages refer to the element’s own size; `position: relative` with `top`/`left` refers to the parent.

Related: [position absolute vs relative](https://markodenic.com/position-absolute-vs-relative/), [CSS hamburger menu](https://markodenic.com/css-hamburger-menu/), [CSS pulse animation](https://markodenic.com/css-pulse-animation/) and [requestAnimationFrame](https://markodenic.com/requestanimationframe/).
