<section>
  <div class="loader">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</section>
*
{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
section
{
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
  animation: changeBgColor 4s steps(1) infinite;
}
@keyframes changeBgColor
{
  0%
  {
    background: #ff0;
  }
  25%
  {
    background: #0f0;
  }
  50%
  {
    background: #ff4786;
  }
  75%
  {
    background: #2da2ff;
  }
  100%
  {
    background: #ff0;
  }
}

.loader
{
  position: relative;
  width: 50px;
  height: 50px;
  background: #000;
  animation: rotate 1s linear infinite;
}
.loader div
{
  position: absolute;
  width: 100%;
  height: 100%;
  background: #000;
  animation: animate 1s linear infinite;
}
@keyframes animate
{
  0%
  {
    transform: rotate(0deg);
  }
  50%,100%
  {
    transform: rotate(180deg);
  }
}

@keyframes rotate
{
  0%
  {
    transform: rotate(90deg);
  }
  50%,100%
  {
    transform: rotate(0deg);
  }
}
.loader div:nth-child(1)
{
  top: -100%;
  left: -2px;
  transform-origin: bottom right;
}
.loader div:nth-child(1)::before
{
  background: #ff0;
}
.loader div:nth-child(2)
{
  right: -100%;
  top: -2px;
  transform-origin: bottom left;
}
.loader div:nth-child(2)::before
{
  background: #0f0;
}
.loader div:nth-child(3)
{
  bottom: -100%;
  left: 2px;
  transform-origin: top left;
}
.loader div:nth-child(3)::before
{
  background: #ff4786;
}
.loader div:nth-child(4)
{
  left: -100%;
  top: 2px;
  transform-origin: top right;
}
.loader div:nth-child(4)::before
{
  background: #2da2ff;
}
.loader:before,
.loader div::before
{
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  bottom: 2px;
  background: #fff;
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.