Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

translate — independent element translation

The translate property moves an element along X, Y, and optionally Z independently of transform. It changes visual position while preserving the element’s place in layout.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

translate: none | <length-percentage> [ <length-percentage> <length>? ]?;

translate takes space-separated X, Y, and Z values; omitted coordinates are 0px. X and Y accept lengths and percentages; Z accepts only a length. Percentages reference the width and height of the reference box selected by transform-box.

Initially none, it is not inherited. Unlike none, even translate: 0px creates a stacking context and containing block for descendants. translate does not replace transform: composition order is translate, rotate, scale, then transform when no motion path is involved.

Translation does not reposition neighboring elements in layout. In the example, 50% of the 100px width moves the element 50px right; 10px moves it down. Its size stays unchanged.

Examples

<!doctype html>
<meta charset="utf-8">
<title>translate</title>
<style>
  body { margin: 0; }
  #box {
    width: 100px;
    height: 60px;
    background: teal;
    translate: 50% 10px;
  }
</style>
<div id="box"></div>
<pre id="result"></pre>
<script>
  const rect = document.querySelector('#box').getBoundingClientRect();
  document.querySelector('#result').textContent =
    `x=${rect.x}, y=${rect.y}, width=${rect.width}, height=${rect.height}`;
</script>

Result

x=50, y=10, width=100, height=60

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources