CSS Reference ยท Transforms, Transitions and Animations
The translate property
Reference for the CSS translate property: move an element with its own property, independent of transform, with one, two or three values and easy animation.
The translate property moves an element along the x, y and optionally z axis, just like the translate() functions inside transform, but as a property of its own. That means you can set, override or animate the movement without repeating (or accidentally erasing) a rotate() or scale() that lives in transform.
Like all transforms, it does not affect layout: the element's original space stays reserved.
.card:hover { translate: 0 -4px; }
Try it
Syntax
translate: none | <length-percentage> [ <length-percentage> <length>? ]?;
- Initial value:
none - Applies to: transformable elements
- Inherited: no
- Animatable: yes
- Computed value:
none, or a pair or triple with absolute lengths and percentages
Values
| Value | Description |
|---|---|
| One value | Horizontal move; vertical is 0. translate: 20px equals translateX(20px). |
| Two values | Horizontal and vertical move. |
| Three values | Horizontal, vertical and depth (z). The third must be a length, not a percentage. |
none |
No translation. |
Percentages refer to the element's own width (x) and height (y).
Usage notes
- Order of application. The individual properties apply in this order:
translate, thenrotate, thenscale, thentransform. Arotateset via therotateproperty therefore happens after the move, unlike a list insidetransformwhere order is yours to choose. - Easy hover effects. Because the property is separate, a
:hoverrule only needstranslate: ...and does not have to copy the basetransform. - Same side effects as transform. A non-
nonevalue creates a stacking context and a containing block for fixed and absolute descendants. - Centering trick.
translate: -50% -50%aftertop: 50%; left: 50%still works for absolutely positioned elements, but grid orinsetwithmargin: autois often simpler. - Reduced motion. Large movements should respect
prefers-reduced-motion.
Browser support
Individual transform properties are newer than transform. They are available in current versions of the major browsers, but check a compatibility table before relying on them for older ones.
Related
rotate,scaletransform,translate()and friends- Lesson: 2D Transforms