Rotating Circle

Sometimes web pages display a circle to indicate the page is performing an action. It could indicate loading data or sending a GET or POST request. It is a good UX feature to show that the operation is underway and may take some time. Look at this circle:

Doing...

Here is the code, split into three sections: HTML, CSS, and JavaScript (which modifies the DOM directly). The HTML is the simplest:

<div id="processor" class="processor">
  <div class="loadingCircle"></div>
  <div class="loadingMessage">Doing...</div>
</div>

CSS creates a circle and animates it with a continuous rotation loop:

.processor {
  margin: 20px;
  display: none;
  position: relative;
  height: 90px; width: 90px;
  box-sizing: border-box;
  color: inherit;
  background-color: transparent;
  border-radius: 50%;
}
.loadingCircle {
  position: relative;
  width: 100%; height: 100%;
  box-sizing: border-box;
  border-radius: 50%;
  border-top: 8px solid #68e;
  border-right: 8px solid #246;
  border-left: 8px solid #246;
  border-bottom: 8px solid #246;
  animation: 1s linear 0s infinite rotate;
}
@keyframes rotate { 0% {transform: rotate(0deg);} 100% {transform: rotate(360deg);} }
.loadingMessage{
  position: absolute;
  width: 100%; top: 50%;
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  text-align: center;
}

Here is a fetch example. Of course, it could be something else, but this is a very common use case. It simply shows the processor div (its default display property is set to none) right when fetching starts and hides it afterward:

function fetchData() {
  const procdisp = document.getElementById('processor');
  procdisp.style.display = 'block';
  fetch('https://example.com/data.json')
    .then(r => r.json())
    .then(data => {
      procdisp.style.display = 'none';
      console.log(data);
    })
    .catch(err => console.error(err));
}

Page published: January 01, 2026

Tags: vanillajs dom ux ui