CSS translate Property

Change position of an element:

Definition and Usage

The translate property allows you to change the position of elements.

The translate property defines x- and y-coordinates of an element in 2D. You can also define the z-coordinate to change position in 3D.

Coordinates can be given as only x-coordinates, x- and y-coordinates, or x-, y- and z-coordinates.

To better understand the translate property, view a demo.

Example:

Result

CSS 2D Transforms

The CSS transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, and skew elements.

Mouse over the element below to see a 2D transformation:

CSS 2D Transforms Functions

With the CSS transform property you can use the following 2D transformation functions:

The CSS rotate() Function

The rotate() function rotates an element clockwise or counter-clockwise according to a given degree.

The following example rotates the <div> element clockwise with 20 degrees:

Example

Result

The CSS scale() Function

The scale() function increases or decreases the size of an element (according to the parameters given for the width and height).

The following example increases the <div> element to be two times of its original width, and three times of its original height:

Example

Result

The CSS scaleX() Function

The scaleX() function increases or decreases the width of an element.

The following example increases the <div> element to be two times of its original width:

Example

Result

The CSS scaleY() Function

The scaleY() function increases or decreases the height of an element.

The following example increases the <div> element to be three times of its original height:

Example

Result

The CSS skew() Function

The skew() function skews an element along the X and Y-axis by the given angles.

The following example skews the <div> element 20 degrees along the X-axis, and 10 degrees along the Y-axis:

Example

The CSS skewX() Function

The skewX() function skews an element along the X-axis by the given angle.

The following example skews the <div> element 20 degrees along the X-axis:

Example

Result

The CSS skewY() Function

The skewY() function skews an element along the Y-axis by the given angle.

The following example skews the <div> element 20 degrees along the Y-axis:

Example

Result

The CSS matrix() Function

The matrix() function combines all the 2D transform functions into one.

The matrix() function take six parameters, containing mathematic functions, which allows you to rotate, scale, move (translate), and skew elements.

The parameters are as follow: matrix(scaleX(), skewY(), skewX(), scaleY(), translateX(), translateY())

 

Example

Result

CSS 2D Transform Functions

Function Description
matrix() Defines a 2D transformation, using a matrix of six values
translate() Defines a 2D translation, moving the element along the X- and the Y-axis
translateX() Defines a 2D translation, moving the element along the X-axis
translateY() Defines a 2D translation, moving the element along the Y-axis
scale() Defines a 2D scale transformation, scaling the elements width and height
scaleX() Defines a 2D scale transformation, scaling the element’s width
scaleY() Defines a 2D scale transformation, scaling the element’s height
rotate() Defines a 2D rotation, the angle is specified in the parameter
skew() Defines a 2D skew transformation along the X- and the Y-axis
skewX() Defines a 2D skew transformation along the X-axis
skewY() Defines a 2D skew transformation along the Y-axis