# translateZ()

> The `translateZ()` CSS function moves an element from its current position along the Z-axis.

## Why does translateZ() do nothing in CSS?

The function that moves an element along the Z-axis in 3D space. It adjusts the depth of the element, making it appear closer or farther away from the viewer, adding a sense of 3D perspective to the design.

- Topic: Transformations
- Type: function
- Browser support: Chrome 12+, Chrome Android 18+, Edge 12+, Firefox 10+, Firefox Android 10+, Safari 4+, Safari iOS 3.2+

## Example

Wrong:

```css
.card:hover {
  transform: translateZ(50px);
}
```

Right:

```css
.scene {
  perspective: 800px;
}
.card:hover {
  transform: translateZ(50px);
}
```

With `perspective` on the parent, moving along the Z-axis makes the card look closer instead of having no visible effect.

## Common mistakes

- Using `translateZ()` without any perspective and seeing no change.
- Adding `translateZ(0)` to many elements, wasting memory on extra layers.

## Key points

- A `perspective` is set on the parent or with `perspective()` when `translateZ()` should be visible.
- `will-change: transform` is used to hint a layer instead of the `translateZ(0)` hack.
- `translateZ()` gets a length, never a percentage.

## Interview questions

### Why do people use translateZ(0)?

It was a hack to push an element onto its own compositor layer. `will-change: transform` expresses the same intent more clearly.

### Can translateZ() take a percentage?

No. It accepts only a length, because an element has no depth to take a percentage of.

## Related cards

- [perspective](https://wonderium.dev/css/perspective-property.md)
- [translate3d()](https://wonderium.dev/css/translate3d.md)
- [transform-style](https://wonderium.dev/css/transform-style.md)
- [will-change](https://wonderium.dev/css/will-change.md)
- [transform](https://wonderium.dev/css/transform.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/translate-z
- Last updated: 2026-11-25
