Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS rotate Property

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

Photo Credit to CodeToFun

🙋 Introduction

The rotate property in CSS is used to rotate elements in a two-dimensional space. This transformation is part of the CSS Transforms module and allows you to rotate elements by a specified angle.

This property is particularly useful for creating dynamic and visually interesting web designs.

💡 Syntax

The syntax for the rotate property is straightforward. It can be applied to any element, and you can specify the angle of rotation using degrees, gradians, radians, or turns.

Syntax
Copied
Copy To Clipboard
element {
  transform: rotate(angle);
}

Here, angle can be a value in degrees (deg), gradians (grad), radians (rad), or turns (turn).

🎛️ Default Value

The default value of the rotate property is 0deg, which means no rotation is applied.

🏠 Property Values

ValueDescription
degreesA value in degrees, such as 45deg, 90deg, etc.
gradiansA value in gradians, such as 50grad.
radiansA value in radians, such as 0.5rad.
turnsA value in turns, such as 0.25turn.

📄 Example

In this example, we'll rotate a square div by 45 degrees.

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 rotate Example</title>
  <style>
    .rotate-box {
      width: 100px;
      height: 100px;
      background-color: lightblue;
      transform: rotate(45deg);
    }
  </style>
</head>
<body>
  <h1>Div with Rotate Transformation</h1>
  <div class="rotate-box"></div>
</body>
</html>

🖥️ Browser Compatibility

The rotate property is supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The rotate property is a powerful tool for web developers looking to add dynamic transformations to their elements.

By rotating elements, you can create engaging and visually appealing designs. Experiment with different angles and see how this property can enhance the look and feel of 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