<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>How to add loader in website | Atul Prajapati</title>
</head>
<body>
  <div class="spinner-wrapper">
    <div class="spinner">
      
    </div>
  </div>
  
  <div class="main-content"></div>
</body>
</html>
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html{
  font-size: 10px;
}

.spinner-wrapper{
    width: 100%;
    height: 100%;
    background-color: #f8f6f6;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .spinner {
    position: relative;
    width: 8rem;
    height: 8rem;
    border-radius: 50%;
  }
  
  .spinner::before,
  .spinner:after{
    content: "";
    position: absolute;
    border-radius: 50%;
  }
  
  .spinner:before {
    width: 100%;
    height: 100%;
    background-image:linear-gradient(90deg, #c59d5f 0%,#515151 100% );
    animation: spin .5s infinite linear;
  }
  
  .spinner:after {
    width: 90%;
    height: 90%;
    background-color: #f3f0f0;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/*Simulate page content*/
.main-content{
    width: 100%;
    height: 100vh;
    background: url("https://source.unsplash.com/random/4000x4000") center no-repeat;
    background-size: cover;
}
let spinnerWrapper = document.querySelector('.spinner-wrapper');

window.addEventListener('load', function(){
  spinnerWrapper.style.display= 'none';
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.