
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - translate Property
The translate Property
The translate property of CSS allows you to move an element along the X-axis (horizontal), Y-axis (vertical), and Z-axis (depth).
The translate property is similar to the translate() function of the transform property. The only difference between the two is that the latter does not support the Z-axis setting.
Syntax
The syntax for the CSS translate property is as follows:
translate: x-axis y-axis z-axis | none;
Possible values
Value | Description |
---|---|
none | It specifies no translation should be applied. |
x-axis | It specifies translation along the X-axis. If one value is specified with the translate property, then it specifies translation in the x-axis. |
y-axis | It specifies translation along the Y-axis. If two values are specified with the translate property, then the first value specifies translation in the x-axis and the second value in the y-axis. To specify translation only the in y-axis, specify the first value as 0px. |
z-axis | It specifies translation along the Z-axis. If three values are specified with the translate property, then the first, second, and third value specifies translation in the x-axis, y-axis, and z-axis respectively. To specify translation only in the z-axis, specify the first two values as 0px. |
You can use either <length> or <percentage> to specify the value of the translate property.
Applies to
All the transformable elements.
CSS translate Property with none Value
To specify that there should not be any translation effect on any axis, we use the translate property with none value.
Example
The following example sets the translate property to none which disables the translation effect on the div box.
<html> <head> <style> .box { height: 100px; width: 100px; display: inline-block; padding: 10px; border: 1px solid black; transition: all 0.3s ease; } .box:hover { background-color: #04af2f; translate: none; } </style> </head> <body> <div class="box"></div> </body> </html>
CSS translate on X-Axis
You can use a single value with the translate property to move an element on the horizontal axis. You can either use length or percentage value for this.
Example
In this example, we have used a positive length value on the first box and a negative percentage value on the second box with the translate property. The first box will move to the right and the second box will move to the left on the x-axis.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { height: 100px; width: 200px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 10px; } .box2:hover { background-color: #031926; translate: -10%; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on x-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
CSS translate on Y-Axis
To translate an element on the y-axis, you need to use a double value with the translate property while setting the first value to 0.
Example
In this example, we have used a positive length value on the first box and a negative percentage value on the second box with the translate property. The first box will move downwards and the second box will move upwards on the y-axis.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { height: 150px; width: 200px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 0px 15px; } .box2:hover { background-color: #031926; translate: 0% -15%; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on y-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
CSS translate on Z-Axis
To translate an element on the z-axis, you need to use a triple value with the translate property while setting the first two values to 0.
Example
In this example, we have used a positive and negative length value on the first box and second box respectively with the translate property. The first box will appear to move closer to the screen while the second box will move away from the screen.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { perspective: 100px; height: 150px; width: 200px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 0 0 15px; } .box2:hover { background-color: #031926; translate: 0 0 -10px; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on z-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
CSS translate on X and Y Axes
You can translate an element on both the x and y axes by using a double value with the translate property.
Example
In this example, we have used two values with the translate property. The first and second value moves the box in horizontal and vertical directions respectively.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { height: 150px; width: 250px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 15px 10px; } .box2:hover { background-color: #031926; translate: -15% -15%; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on both x and y-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
CSS translate on Y and Z Axes
You can translate an element on both the y and z-axes by using a double value with the translate property while setting the x-axes value as 0.
Example
In this example, we have used two values with the translate property. The second and third value moves the box to the y-axis and z-axis respectively.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { perspective: 100px; height: 150px; width: 250px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 0px 15px 10px; } .box2:hover { background-color: #031926; translate:0 -15% 10px; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on both y and z-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
CSS translate on X and Z Axes
To translate an element on both the x and z-axes, you can use a double value with the translate property while setting the y-axis value to 0.
Example
In this example, we have used two values with the translate property. The first and third value moves the box to the x-axis and z-axis respectively.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { perspective: 100px; height: 150px; width: 250px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 15px 0 15px; } .box2:hover { background-color: #031926; translate: -15% 0 10px; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on both x and z-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
CSS translate on X, Y and Z Axes
To translate an element in all directions, you can use three values with the translate property.
Example
In this example, we have used three values with the translate property. The first, second, and third value moves the box horizontally, vertically, and in the z-axis respectively.
<!DOCTYPE html> <html lang="en"> <head> <style> .container { perspective: 100px; height: 150px; width: 250px; padding: 10px; border: 1px solid black; margin: auto; display: flex; justify-content: space-around; align-items: center; background-color: #f0f0ff; } .box { height: 80px; width: 80px; border: 1px solid black; display: inline-block; transition: all 0.3s ease; background-color: white; } .box1:hover { background-color: #04af2f; translate: 15px 15% 15px; } .box2:hover { background-color: #031926; translate: -15% -10px 10px; } </style> </head> <body> <h2>CSS translate Property</h2> <p>Translation on x,y, and z-axis.</p> <div class="container"> <div class="box box1"></div> <div class="box box2"></div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
translate | 104.0 | 104.0 | 72.0 | 14.1 | 90.0 |