css

Infinite Rotation with CSS Animation

Last updated: 21.02.2026
Views: 223

An infinitely rotating element on a website is an interesting way to attract the user’s attention. It is quite easy to implement such an element using CSS. Here is an example of CSS code for infinite clockwise rotation.

CSS

.rotate-clockwise {
  animation-name: clockwise;
  animation-duration: 3s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

@keyframes clockwise {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

CSS class .rotate-clockwise can be written in one line.

.rotate-clockwise {
  animation: 3s linear infinite clockwise;
}

If you need to rotate counterclockwise, then this is also easy to do.

CSS

.rotate-counterclockwise {
  animation-name: counterclockwise;
  animation-duration: 3s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

@keyframes counterclockwise {
  0% {
    transform: rotate(360deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

You can see an example of working code on Codepen: https://codepen.io/igorrybalko/pen/XJrLRvg

author
Author: Igor Rybalko
I have been working as a front-end developer since 2014. My main technology stack is Vue.js and WordPress.

Similar posts:

  • How to Add a Favicon to a Website
    A favicon is a website icon. The easiest way to add it to the page is to put an icon with the name favicon.ico 16x16 pixels in the root of the site. Or set a path by writ...
  • How to Hide Scrollbar Using CSS
    There are several ways to hide the scrollbar using CSS, depending on whether you want to completely remove scrolling or just hide the visual appearance of the scrollbar. ...
  • Image Scaling Problem in Outlook
    When I was composing HTML emails, I encountered the fact that in desktop Outlook (it turns out that someone else uses it) the images were displayed at a strange scale. Al...

One response to “Infinite Rotation with CSS Animation”

  1. tlover tonet says:

    Thanks for ones marvelous posting! I actually enjoyed reading it, you happen to be a great author.I will ensure that I bookmark your blog and definitely will come back in the foreseeable future. I want to encourage one to continue your great work, have a nice holiday weekend!

Leave a Reply

Your email address will not be published. Required fields are marked *