Course contentsShow
← Web Development
Lesson 531 of 2,9829. CSS Transitions and AnimationsFree lesson

Rotating Elements with rotate()

Rotating elements around their center point using the rotate() function with degree or turn units.

Rotating Elements with rotate()

What you'll learn: How to spin any HTML element around its center using CSS's rotate() transform function.


What Is Rotation in CSS?

The rotate() function lets you turn an element clockwise or counterclockwise around a fixed point (by default, its center). Think of it like spinning a piece of paper on a table while keeping your finger pressed in the middle—the paper rotates around that center point.

How rotate() Works

You apply rotate() using the transform property with either degrees (deg) or turns (turn) as units:

.element {
  transform: rotate(45deg); /* Rotates 45 degrees clockwise */
}
  • Positive values rotate clockwise
  • Negative values rotate counterclockwise
  • 1 turn = 360 degrees (a complete circle)

Practical Examples

.card {
  transform: rotate(15deg); /* Slight tilt */
}

.spinner {
  transform: rotate(180deg); /* Upside down */
}

.clock-hand {
  transform: rotate(-90deg); /* 90° counterclockwise */
}

.full-spin {
  transform: rotate(1turn); /* Complete 360° rotation */
}

Degrees vs Turns

Both units achieve the same result:

  • rotate(90deg) = rotate(0.25turn) (quarter turn)
  • rotate(360deg) = rotate(1turn) (full circle)

Use degrees for precise angles and turns when thinking in fractions of a circle.

Combining with Other Transforms

You can rotate alongside other transforms you've already learned:

.tilted-card {
  transform: translate(50px, 20px) scale(1.2) rotate(10deg);
}

Key Takeaway: The rotate() function spins elements around their center point using degree (deg) or turn (turn) units—positive values go clockwise, negative go counterclockwise.