CSS translate Property

The CSS translate property moves an element horizontally, vertically, or in three-dimensional space without changing its position in the document layout.

It is an individual transform property that allows you to control translation separately from rotation and scaling. You can use lengths, percentages, and combinations of values to create movement effects, align elements, and build interactive transitions.

translate Syntax

The translate property accepts one, two, or three space-separated values. The first controls horizontal movement, the second controls vertical movement, and the optional third controls movement along the Z-axis.

Basic Syntax

.example {
  translate: 50px;
}

Horizontal Translation

.example {
  translate: 50px 0;
}

Vertical Translation

.example {
  translate: 0 30px;
}

Two-Axis Translation

.example {
  translate: 50px 30px;
}

Percentage Translation

.example {
  translate: 50% 25%;
}

Three-Dimensional Translation

.example {
  translate: 50px 30px 100px;
}

No Translation

.example {
  translate: none;
}

CSS-Wide Keywords

.example {
  translate: initial;
}
.example {
  translate: inherit;
}
.example {
  translate: unset;
}
.example {
  translate: revert;
}
.example {
  translate: revert-layer;
}

Invalid Examples

.example {
  translate: 50px, 30px;
}
.example {
  translate: 50px 30px 25%;
}
.example {
  translate: 45deg;
}

The values must be separated by spaces rather than commas. The third value must be a length, not a percentage, and angle values are not valid.

Property Values

Value Description
none Applies no translation. This is the initial value.
<length> Moves the element horizontally using a length value.
<percentage> Moves the element horizontally by a percentage of its transform reference box.
<length-percentage> <length-percentage> Specifies horizontal and vertical translation.
<length-percentage> <length-percentage> <length> Specifies translation along the X, Y, and Z axes.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to Transformable elements
Computed value none or a pair of computed length-percentage values and an optional absolute Z-axis length
Animation type By computed value
Percentages Relative to the corresponding dimension of the transform reference box
Specification CSS Transforms Level 2

Note: The translate property is independent of the transform property. It can be combined with rotate, scale, and transform without replacing their declarations.

How It Works

The translate property changes an element's visual position while preserving its original layout space.

Original Position

.box {
  translate: none;
}

Move Horizontally

.box {
  translate: 50px;
}

Move Vertically

.box {
  translate: 0 30px;
}

Move Along Both Axes

.box {
  translate: 50px 30px;
}

Understanding the Result

Positive X values move an element to the right in the usual left-to-right coordinate system. Negative X values move it left. Positive Y values move it down, while negative Y values move it up.

Layout Behavior

Translation does not cause surrounding elements to rearrange themselves around the element's new visual position. The original layout space remains reserved.

Coordinate System

Translation uses the element's transform coordinate system, which can be affected by other transformations and the element's ancestors.

Horizontal Translation

Horizontal translation moves an element along the X-axis.

Move Right

.box {
  translate: 50px;
}

Move Left

.box {
  translate: -50px;
}

Using rem Units

.box {
  translate: 2rem;
}

Using Percentages

.box {
  translate: 50%;
}

The percentage is calculated using the width of the element's transform reference box, not the width of its parent container.

Important Consideration

Translation is visual movement. It does not replace margin, padding, or layout positioning when surrounding elements need to respond to the new location.

Vertical Translation

Vertical translation moves an element along the Y-axis.

Move Down

.box {
  translate: 0 40px;
}

Move Up

.box {
  translate: 0 -40px;
}

Using Percentages

.box {
  translate: 0 -50%;
}

The vertical percentage is calculated using the height of the transform reference box.

Hover Movement

.card {
  translate: 0 0;
  transition: translate 0.3s ease;
}
.card:hover {
  translate: 0 -8px;
}

This technique is useful for small visual effects, such as lifting a card when it is hovered.

Two-Axis Translation

Two-axis translation combines horizontal and vertical movement in a single declaration.

Move Right and Down

.box {
  translate: 40px 20px;
}

Move Left and Up

.box {
  translate: -40px -20px;
}

Move Right and Up

.box {
  translate: 40px -20px;
}

Move Left and Down

.box {
  translate: -40px 20px;
}

Using Different Units

.box {
  translate: 2rem 15px;
}

Important Consideration

The first value always represents the X-axis, and the second represents the Y-axis.

Percentage Values

Percentage translation values are calculated relative to the element's transform reference box.

Horizontal Percentage

.box {
  translate: 50%;
}

This moves the element horizontally by half the width of its transform reference box.

Vertical Percentage

.box {
  translate: 0 50%;
}

This moves the element vertically by half the height of its transform reference box.

Centering an Absolutely Positioned Element

.container {
  position: relative;
}
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
}

The top and left declarations position the element's top-left corner at the center of the containing block. The negative translation offsets the element by half its own reference-box dimensions.

Combining Lengths and Percentages

.box {
  translate: calc(50% + 10px) calc(-50% + 5px);
}

Important Consideration

For typical HTML elements, the transform reference box corresponds to the border box. The transform-box property can change which box is used.

Three-Dimensional Translation

The translate property can also move an element along the Z-axis.

Three-Axis Syntax

.box {
  translate: 20px 30px 100px;
}

The third value controls movement along the Z-axis and must be a length.

Move Toward the Viewer

.box {
  translate: 0 0 100px;
}

Move Away From the Viewer

.box {
  translate: 0 0 -100px;
}

Using Perspective

.scene {
  perspective: 600px;
}
.box {
  translate: 0 0 100px;
}

Perspective makes depth movement visually apparent. A positive Z translation generally makes the element appear closer and larger, while a negative value makes it appear farther away and smaller.

Combining Three-Dimensional Transforms

.box {
  translate: 20px 0 80px;
  rotate: y 25deg;
}

Invalid Z-Axis Percentage

.box {
  translate: 0 0 50%;
}

The Z-axis value cannot be a percentage.

Important Consideration

Without perspective or other three-dimensional context, movement along the Z-axis may not produce an obvious visual size change.

translate vs. transform

The translate property and the translate() transform function can produce similar visual movement, but they are declared differently.

Using the translate Property

.box {
  translate: 50px 20px;
}

Using the transform Property

.box {
  transform: translate(50px, 20px);
}

Combining Translation and Rotation

.box {
  translate: 50px 20px;
  rotate: 15deg;
}

Equivalent Transform Functions

.box {
  transform: translate(50px, 20px) rotate(15deg);
}

These examples can produce equivalent results when no other transforms affect the element.

Independent Transform Properties

.box {
  translate: 50px 20px;
  rotate: 15deg;
  scale: 1.2;
}

Each individual transform property can be updated separately without rewriting a combined transform function list.

Using Both Properties

.box {
  translate: 50px 0;
  transform: rotate(15deg);
}

Both declarations contribute to the final transformation. The transform declaration does not replace the independent translate property.

Transform Order

Individual transform properties are applied in a defined order: translation, rotation, scaling, and then the transformations specified by transform.

Individual Properties

.box {
  translate: 50px 0;
  rotate: 30deg;
  scale: 1.2;
}

Adding a Transform Function

.box {
  translate: 50px 0;
  rotate: 30deg;
  scale: 1.2;
  transform: skewX(10deg);
}

Declaration Order Does Not Change the Transform Order

.box {
  scale: 1.2;
  rotate: 30deg;
  translate: 50px 0;
}

Rearranging the individual property declarations does not change their defined transform composition order.

Transform Function Order

.first {
  transform: translateX(50px) rotate(30deg);
}
.second {
  transform: rotate(30deg) translateX(50px);
}

Unlike individual transform properties, the order of functions inside a transform declaration affects the result.

Important Consideration

Combining independent transform properties with a transform function list can produce results that differ from simply placing all functions in one declaration.

Transitions and Animations

The translate property supports smooth transitions and CSS keyframe animations.

Hover Transition

.button {
  translate: 0 0;
  transition: translate 0.3s ease;
}
.button:hover {
  translate: 0 -5px;
}

Horizontal Movement

.box {
  translate: 0;
  transition: translate 0.5s ease-in-out;
}
.box:hover {
  translate: 100px;
}

Multiple Transitions

.card {
  translate: 0 0;
  opacity: 0.8;
  transition: translate 0.3s ease, opacity 0.3s ease;
}
.card:hover {
  translate: 0 -8px;
  opacity: 1;
}

Keyframe Animation

@keyframes slide-in {
  from {
    translate: -100px 0;
    opacity: 0;
  }
  to {
    translate: 0 0;
    opacity: 1;
  }
}
.box {
  animation: slide-in 0.6s ease-out;
}

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .box {
    transition: none;
    animation: none;
  }
}

Important Consideration

Translation is often suitable for movement effects because it does not require the browser to recalculate surrounding layout positions for each frame. Actual rendering performance depends on the element and other styles.

The translate property belongs to the CSS transform system and works with several related properties.

transform

.box {
  transform: translateX(50px);
}

Applies transformations using one or more transform functions.

rotate

.box {
  rotate: 30deg;
}

Rotates an element independently of translation.

scale

.box {
  scale: 1.2;
}

Changes an element's visual size independently of translation.

transform-origin

.box {
  transform-origin: center;
}

Defines the origin used for transformations such as rotation and scaling.

transform-box

.box {
  transform-box: border-box;
}

Controls the reference box used for transformations and percentage translation calculations.

perspective

.scene {
  perspective: 600px;
}

Provides perspective for three-dimensional transformations.

transition

.box {
  transition: translate 0.3s ease;
}

Animates changes to the translation values.

Inheritance

The translate property is not inherited. Child elements do not automatically receive their parent's declared translation value.

Parent Element

.parent {
  translate: 50px 0;
}

Child Element

.child {
  translate: none;
}

Although the child does not inherit the parent's value, it still moves visually with its transformed parent.

Explicit Inheritance

.child {
  translate: inherit;
}

Restore the Initial Value

.child {
  translate: initial;
}

This restores the initial value of none.

Using unset

.child {
  translate: unset;
}

Because the property is not inherited, unset restores its initial value.

Practical Examples

Lift a Button

.button {
  translate: 0 0;
  transition: translate 0.2s ease-out;
}
.button:hover,
.button:focus-visible {
  translate: 0 -4px;
}

Move a Card

.card {
  translate: 0 0;
  transition: translate 0.3s ease;
}
.card:hover {
  translate: 0 -8px;
}

Center an Element

.container {
  position: relative;
}
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
}

Slide a Panel Into View

.panel {
  translate: 100% 0;
  transition: translate 0.4s ease;
}
.panel.is-open {
  translate: 0 0;
}

Move an Icon

.icon {
  display: inline-block;
  translate: 0 0;
  transition: translate 0.2s ease;
}
.link:hover .icon,
.link:focus-visible .icon {
  translate: 5px 0;
}

Combine Translation and Scaling

.card {
  translate: 0 0;
  scale: 1;
  transition: translate 0.3s ease, scale 0.3s ease;
}
.card:hover {
  translate: 0 -6px;
  scale: 1.03;
}

Three-Dimensional Movement

.scene {
  perspective: 700px;
}
.card {
  translate: 0 0 0;
  transition: translate 0.4s ease;
}
.card:hover {
  translate: 0 0 80px;
}

translate Example

This example demonstrates horizontal, vertical, and diagonal translation. Hover over or keyboard-focus each box to see how the translate property changes its visual position.

HTML Example

<div class="translate-demo">
  <div class="translate-item">
    <div class="translate-box translate-x" tabindex="0">X-Axis</div>
  </div>
  <div class="translate-item">
    <div class="translate-box translate-y" tabindex="0">Y-Axis</div>
  </div>
  <div class="translate-item">
    <div class="translate-box translate-xy" tabindex="0">X + Y</div>
  </div>
</div>

CSS Example

.translate-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 20px;
}
.translate-item {
  width: 160px;
  height: 130px;
  padding: 10px;
  background-color: #e5e7eb;
  border-radius: 4px;
}
.translate-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 90px;
  height: 60px;
  background-color: #2563eb;
  color: #fff;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  translate: 0 0;
  transition: translate 0.5s ease;
}
.translate-box:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}
.translate-x:hover,
.translate-x:focus-visible {
  translate: 40px 0;
}
.translate-y:hover,
.translate-y:focus-visible {
  translate: 0 40px;
}
.translate-xy:hover,
.translate-xy:focus-visible {
  translate: 40px 40px;
}
@media (prefers-reduced-motion: reduce) {
  .translate-box {
    transition: none;
  }
}
Browser Result
X-Axis
Y-Axis
X + Y

Understanding the Results

Each box begins at its original position. When hovered or focused, it moves according to its assigned translation values.

X-Axis

The first box moves 40 pixels to the right.

Y-Axis

The second box moves 40 pixels downward.

X + Y

The third box moves 40 pixels right and 40 pixels down.

Experiment With Negative Values

.translate-x:hover {
  translate: -20px 0;
}

The first box now moves to the left when hovered.

Experiment With Percentages

.translate-xy:hover {
  translate: 50% 50%;
}

The third box moves by half its own reference-box width and height.

Experiment With Duration

.translate-box {
  transition: translate 1s ease-in-out;
}

The movement takes one second and follows an ease-in-out timing curve.

Accessibility Considerations

Translation can create useful visual feedback, but movement should not interfere with readability, navigation, or user preferences.

Respect Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .animated-element {
    transition: none;
    animation: none;
  }
}

Avoid Excessive Movement

Large or repeated movements can be distracting. Use subtle translation effects when possible.

Preserve Keyboard Accessibility

Moving an interactive element does not change its position in the keyboard focus order. Ensure it remains visible and usable.

Maintain Visible Focus Indicators

Focus indicators should remain visible when an element is translated.

Avoid Hiding Essential Content

Translated elements can move outside their containers or the viewport. Make sure important content remains accessible.

Do Not Rely on Motion Alone

Provide other visual or textual cues when translation communicates a state change.

Check Overlapping Content

Because translation does not change document layout, moved elements can overlap nearby content.

Support Different Viewport Sizes

Test translation distances on narrow screens and at increased browser zoom levels.

Common Mistakes

Using Commas Between Values

.box {
  translate: 50px, 30px;
}

The translate property uses space-separated values.

Using a Percentage for the Z-Axis

.box {
  translate: 0 0 50%;
}

The third value must be a length.

Using Angle Values

.box {
  translate: 45deg;
}

Angles belong to rotation properties and functions.

Confusing translate With translate()

.box {
  translate: translate(50px, 20px);
}

The translate() function belongs inside the transform property.

Expecting Layout Reflow

Translation changes visual position but does not cause surrounding elements to rearrange themselves.

Using Percentages Relative to the Parent

Percentage translation values are based on the transform reference box, not automatically on the parent element.

Forgetting Perspective

Z-axis translation may not produce an obvious depth effect without perspective.

Expecting Inline Elements to Translate

Non-replaced inline elements are not transformable. Use an appropriate display value, such as inline-block, when necessary.

Overlooking Transform Composition

Independent transform properties combine with transform in a defined order.

Ignoring Reduced Motion Preferences

Provide alternatives for users who prefer reduced motion.

Important Considerations

Keep the following points in mind when using translate:

  • The property moves elements along the X, Y, and optional Z axes.
  • The initial value is none.
  • The property is not inherited.
  • It applies to transformable elements.
  • One value specifies horizontal translation.
  • Two values specify horizontal and vertical translation.
  • Three values specify horizontal, vertical, and depth translation.
  • Values must be separated by spaces rather than commas.
  • Positive and negative values move elements in opposite directions.
  • Horizontal and vertical values accept lengths and percentages.
  • The Z-axis value must be a length.
  • Percentages are relative to the transform reference box.
  • The transform-box property can affect percentage calculations.
  • Translation does not change the element's reserved layout space.
  • Translated elements can overlap surrounding content.
  • The property is independent of transform.
  • It can be combined with rotate and scale.
  • Individual transforms follow a defined composition order.
  • The property supports transitions and animations.
  • Perspective can make Z-axis movement visually apparent.
  • Translation can be useful for visual movement effects.
  • Rendering performance depends on the complete element and page.
  • Large translation values may move content outside the viewport.
  • Respect reduced motion preferences.
  • Test translated content at different viewport sizes and zoom levels.

Browser Support

The CSS translate property is widely supported in current browsers. It is an individual transform property introduced separately from the older transform: translate() syntax.

Older browser versions may support the translate() transform function without supporting the independent translate property.

For current compatibility information, visit Can I Use? and search for CSS translate.

Basic Declaration

.example {
  translate: 50px 20px;
}

Feature Detection

@supports (translate: 50px 20px) {
  .example {
    translate: 50px 20px;
  }
}

Fallback Example

.example {
  transform: translate(50px, 20px);
}
@supports (translate: 50px 20px) {
  .example {
    transform: none;
    translate: 50px 20px;
  }
}

This fallback uses the older transform function when the independent property is unavailable. The supported version resets the fallback transform to avoid applying translation twice.

Testing Recommendations

Test percentage values, combinations with other transforms, transitions, and three-dimensional effects. Check that fallback declarations do not accidentally duplicate movement.

Specifications

The translate property is defined in the CSS Transforms Level 2 specification.

CSS Transforms Level 2 - Individual Transform Properties

The specification defines individual translation, rotation, and scaling properties, including their syntax, interpolation, and composition with the transform property.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: translate