Skip to main content

Explore your training options in 10 minutes

Rotating Elements with CSS

Felipe Bohórquez - December 29, 2020

The CSS rotate() function skews an element by a certain number of degrees. You can rotate an element clockwise using a positive number of degrees. Or, you can rotate an element anti-clockwise using a negative number.

Today we’ll learn how to rotate elements with CSS. Why should we rotate an element? Rotating elements make your web page more interactive. Used correctly, a rotating element will add to the aesthetics of your site.

While reading this article, please refer to the accompanying repo , so you can see the concepts in action. Knowing how to rotate an element will be a valuable addition to your CSS toolbox.

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

CSS rotate()

The CSS rotate() function lets you rotate an element on a 2D axis. The rotate() function accepts one argument: the angle at which you want to rotate your web element. You can rotate an element clockwise or counter-clockwise.

Let’s take a look at the syntax for the rotate() function:

transform: rotate(angle);

The value “angle” represents the number of degrees the element should rotate. You can specify a rotate that is clockwise using a positive degree number (i.e. 45). Or, you can rotate in the opposite direction using a negative degree value (i.e. -39).

The rotate() function can apply to any HTML element. For instance, you could rotate a paragraph of text. Or you could rotate an image.

A HTML rotate appears as soon as you render the page so there is no visible rotate. To view the rotating in action, you should use a CSS transition . Transitions change the state of an element when an action is taken, such as when a cursor hovers over an element.

rotate() CSS Example

Let’s go ahead and create our HTML page on which to place a rotating box. Let’s add a box as a div and give it a class (let’s name it “rotate”).

<div class="rotate"></div>

Now let’s add some styling to it:

div.rotate {
    width: 50px;
    height: 50px;
    background-color: chocolate;

Refresh. Cool, we have a colored box. With this colored box, we have all that we need to start using the rotate() function.

Screen Shot 2020-08-12 at 8 09 12 PM

In order to rotate our box, we need to discuss the transform property first.

The CSS transform function as the name implies, transforms elements. One of the functions we can apply to it, is rotate() . The transform property can take many other functions and there are many things we can do with transform. Rotate is just one of them.

The rotate function moves an element. It takes one argument: the number of degrees we want to skew the element. Let’s go ahead and apply a 35-degree positive rotation:

Venus, a software engineer at Rockbot

"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"

Venus, Software Engineer at Rockbot

div.rotate {
    width: 50px;
    height: 50px;
    background-color: chocolate;
    transform: rotate(35deg); 

We rotated our box! Tap yourself on the back.

Screen Shot 2020-08-12 at 8 21 25 PM

When to Use the CSS Transform rotate() Function

Rotate allows for fancy UI ideas or rotating images. For example, you can rotate 180 degrees an image. If you need that rotated image somewhere else just save it and use it accordingly.

Another thing you can rotate is text. Let’s say you are creating a layout that mimics a magazine, you can actually rotate the text to add emphasis to text elements.

And that is not all you can do with rotate() . The rotate function allows us to do some really cool animations !

Let’s go ahead and use the CSS :hover selector on our div to actually apply a nice rotation effect:

.rotate:hover {
    transform: rotate(35deg); 
    background-color: deeppink;

Isn’t this cool? 😎


Our box rotates when we hover over it with a mouse. We use the background-color CSS property to change the color of our box when we hover over it.


The CSS rotate() function makes a web element appear at an angle. This function accepts one argument: the number of degrees the element should be rotated. You can specify either a positive or negative degree value.

Rotating elements lets you make your web pages more aesthetically pleasing. For instance, you may apply a rotate to a box when the user hovers over it with their cursor. Or you may decide to rotate a link when a user hovers over it with their mouse. It’s up to you how you use this skill!

Are you interested in learning more about CSS? Check out our complete How to Learn CSS guide for expert advice and guidance on top learning resources.

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

What's Next?

Felipe Bohórquez

About the author: Felipe Bohórquez is a Software Engineer and technical writer at Career Karma. He covers all things frontend and backend development.

Skip to main content