Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS translate Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 18 - Views
⏳ 4 mins
💬 1 Comment
CSS translate Property

Photo Credit to CodeToFun

🙋 Introduction

The translate property in CSS is used to move an element from its current position, both horizontally and vertically.

It is part of the CSS transform property family, which allows developers to manipulate elements in 2D and 3D space without affecting the layout of the document.

💡 Syntax

The syntax for the translate property is as follows:

Syntax
Copied
Copy To Clipboard
transform: translate(tx, ty);
  • tx: Specifies the horizontal translation value.
  • ty: Specifies the vertical translation value.

🎛️ Default Value

The default value is translate(0, 0), which means no translation (no movement) from the element's original position.

🏠 Property Values

ValueDescription
txA length value (px, em, rem, %, etc.) specifying the horizontal translation.
tyA length value (px, em, rem, %, etc.) specifying the vertical translation.

📄 Example

In this example, we'll translate a <div> element horizontally and vertically using the translate property.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS translate Example</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: #3498db;
      transform: translate(50px, 20px);
    }
  </style>
</head>
<body>
  <h1>Box with Translate Transformation</h1>
  <div class="box"></div>
</body>
</html>

🖥️ Browser Compatibility

The translate property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is part of the CSS transform module, which has excellent support across all major browsers.

🎉 Conclusion

The translate property is essential for creating smooth and interactive web experiences by moving elements dynamically on the page.

It is widely supported and offers a straightforward way to manipulate the position of elements without affecting their layout properties. Experiment with different values for tx and ty to achieve the desired visual effects in your web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy