<div class="Cube">
  <div class="Face" front></div>
  <div class="Face" back></div>
  <div class="Face" right></div>
  <div class="Face" left></div>
  <div class="Face" top></div>
  <div class="Face" bottom></div>
</div>
:root {
  --cube-size: 20vmax;
  --light-hue: 260deg;
  --light-saturation: 50%;
  --light-power: 50%;
  --faces-transparency: 50%;
  
  /* Comment this to disable auto color switch */
  animation: color 20s linear infinite;
}


.Cube {
  --cube-half: calc(var(--cube-size) / 2);
  --cube-z: calc(var(--cube-half) * -1);
  --light: var(--light-hue) var(--light-saturation) calc(var(--light-power) + 20%);
  --surface: var(--light-hue) var(--light-saturation) var(--light-power);
  
  width: var(--cube-size);
  height: var(--cube-size);
  position: relative;
  transform-style: preserve-3d;
  transform: translateZ(var(--cube-z));
  animation: rotation 60s infinite linear;
  animation-fill-mode: forwards;
  
  &::before,
  &::after {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    animation: move 1s infinite ease-in-out alternate;
    background: radial-gradient(
      circle at center,
      white,
      hsl(var(--surface))
    );
  }
  
  &::before {
    --from-z: -3vmax;
    --to-z: 6vmax;
    
    mask-image: radial-gradient(
      transparent 0% 40%,
      black 40.1% 60%,
      transparent 60.1% 
    )
  }  

  &::after {
    --from-z: 6vmax;
    --to-z: -3vmax;
    
    mask-image: radial-gradient(
      black 0 10%,
      transparent 10.1% 20%,
      black 20.1% 30%,
      transparent 30.1%
    )
  }
}


.Face { 
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backdrop-filter: blur(2px);
  box-shadow: inset 0 0 3vmax -2vmax hsl(0deg 0% 100% / max(50%, var(--light-saturation)));
  background-image: linear-gradient(
    45deg,
    hsl(var(--surface)),
    hsl(var(--light) / var(--faces-transparency))
  );
}


/* Position each face to the correct side */
[front]  { transform: rotateY(0) translateZ(var(--cube-half)); }
[right]  { transform: rotateY(90deg) translateZ(var(--cube-half)); }
[back]   { transform: rotateY(180deg) translateZ(var(--cube-half)); }
[left]   { transform: rotateY(-90deg) translateZ(var(--cube-half)); }
[top]    { transform: rotateX(90deg) translateZ(var(--cube-half)); }
[bottom] { transform: rotateX(-90deg) translateZ(var(--cube-half)); }


/* Cube animation */
@keyframes rotation { 
  0% {
    transform: translateZ(var(--cube-z)) rotateY(0deg) rotateZ(0deg);
  }

  25% {
    transform: translateZ(var(--cube-z)) rotateY(-90deg) rotateZ(90deg);
  }
  
  50% {
    transform: translateZ(var(--cube-z)) rotateY(-180deg) rotateZ(-90deg);
  }  
  
  75% {
    transform: translateZ(var(--cube-z)) rotateY(90deg) rotateZ(180deg);
  }
}


/* Cube content anmation */

@keyframes move {
  from {
    transform: translateZ(var(--from-z));
  }
  
  to {
    transform: translateZ(var(--to-z));
  }
}









































































































































































































































































































































































































































































































































html {
  block-size: 100%;
  inline-size: 100%;
  background: hsl(var(--light-hue) var(--light-saturation) var(--light-power));
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

body {
  min-block-size: 100%;
  min-inline-size: 100%;
  box-sizing: border-box;
  display: grid;
  margin: 0;
  place-content: center;
  font-family: system-ui;
  perspective: 100vmax;
}

@keyframes color {
  0% {
    --light-hue: 260deg;
    --light-saturation: 50%;
    --light-power: 50%;
  }
  20% {
    --light-hue: 120deg;
    --light-saturation: 50%;
    --light-power: 50%;
  }
  40% {
    --light-hue: 360deg;
    --light-saturation: 50%;
    --light-power: 50%;
  }
  60% {
    --light-hue: 230deg;
    --light-saturation: 50%;
    --light-power: 50%;
  }
  80% {
    --light-hue: 440deg;
    --light-saturation: 50%;
    --light-power: 50%;
  }
  100% {
    --light-hue: 80deg;
    --light-saturation: 50%;
    --light-power: 50%;
  }
}

@use postcss-preset-env {
  stage: 0;
  preserve: false;
  browsers: [
    "last 1 Chrome versions",
    "last 1 Firefox versions",
    "last 1 Safari versions",
    "last 1 Edge versions"
  ]
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdn.jsdelivr.net/npm/what-input/dist/what-input.min.js