CSS rotate()

Sriparno08's avatar
Published Jul 7, 2021Updated Jul 24, 2025
Contribute to Docs

The CSS rotate() function rotates an element around a fixed point by a specified angle. This rotation can either be clockwise or anticlockwise and is commonly used in animations, UI interactions, or creative web layouts.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.
    • Beginner Friendly.
      6 hours

CSS rotate() Syntax

transform: rotate(angle);

Parameters:

  • angle: Defines the degree of rotation. It accepts values in degrees (deg), radians (rad), gradians (grad), or turns (turn).
    • Positive values = Clockwise rotation
    • Negative values = Anticlockwise rotation

Example 1: Basic Rotation in CSS Using rotate()

In this example, the .box element is rotated 45 degrees clockwise from its original position using CSS rotate(), creating a diamond-like appearance:

.box {
width: 100px;
height: 100px;
background-color: coral;
transform: rotate(45deg);
margin: 50px;
}

Here is the output:

The CSS rotate() function rotates a box 45 degrees clockwise from its original position, creating a diamond-like appearance

Example 2: Using rotate() to Rotate on Hover

When a user hovers on the .box element, it rotates 90 degrees, thanks to the smooth transition defined in the CSS:

.box {
width: 100px;
height: 100px;
background-color: mediumseagreen;
transition: transform 0.3s ease-in-out;
margin: 50px;
}
.box:hover {
transform: rotate(90deg);
}

Here is the output:

The CSS rotate() function rotates a box 90 degrees on hover

Example 3: Continuous Rotation in CSS With the Help of rotate()

This example creates a spinning loader by continuously rotating a styled circle using a CSS animation:

.box {
width: 80px;
height: 80px;
margin: 50px;
border: 5px solid lightgray;
border-top: 5px solid steelblue;
border-radius: 50%;
animation: spin 2s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

Here is the output:

A spinning loader created using the CSS rotate() function

Frequently Asked Questions

1. Does CSS rotate() affect layout or just visual appearance?

CSS rotate() is part of the transform property and only affects visual appearance. It doesn’t change the element’s position in the document flow.

2. Can I combine CSS rotate() with other transform functions?

Absolutely. You can combine CSS rotate() with other transform functions by separating them with a space:

transform: scale(1.2) rotate(30deg) translateX(20px);

3. Is CSS rotate() supported across all browsers?

Yes. Modern browsers like Chrome, Firefox, Safari, Edge, and even Internet Explorer 9+ support CSS rotate().

4. How to rotate 45 degrees in CSS?

Here’s how you can use CSS rotate() to rotate 45 degrees:

transform: rotate(45deg);

All contributors

Contribute to Docs

Learn CSS on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.
    • Beginner Friendly.
      6 hours