How to create a simple CSS Loader

hello world

cover for How to create a simple CSS Loader

Loaders are very common in front-end applications. In this article you will see how to create a simple loader using just CSS.

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="./styles.css">
  <title>Simple CSS Loader</title>
  <div class="overlay"></div>
  <div class="loader">
    <div class="loader__spinner"></div>
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  background-color: rgba(0,0,0,0.15);
  width: 100%;
  height: 100%;

.loader {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  transform: translate(-50%, -50%);

.loader__spinner {
  border: 5px solid lightblue;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: rotate 1s infinite linear;
  border-right-color: blue;

@keyframes rotate {
  from {
    transform: rotate(0);
  to {
    transform: rotate(360deg);