<style>
  * {
    box-sizing: border-box;
  }
  html, body {
    align-items: center;
    background: linear-gradient(45deg, rebeccapurple, #dadfe1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0;
    min-height: 100vh;
    padding: 0;
    width: 100vw;
  }
  div {
    background: #f62459;
    height: 50px;
    margin: 40px;
    width: 50px;
  }
  h1 {
    color: #fafafa;
    font-family: 'Arial', sans-serif;
    font-size: 2rem;
    height: 2rem;
  }
</style>
<div class='animating'></div>
<h1></h1>
.animating {
  animation: spin .5s ease-out;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
const spinner = document.querySelector('div')
const label = document.querySelector('h1')

const update = () => {
  spinner.classList.remove('animating')
  const interval = Math.floor(Math.random() * 5000)
  label.innerText = `Spinning in ${interval}ms`
  setTimeout(() => {
    spinner.classList.add('animating')
  }, interval)
}

spinner.addEventListener('animationend', update)
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.