<div class="wrapper">
  <div class="cube">
    <div>Top</div>
    <div>Bottom</div>
    <div>Left</div>
    <div>Right</div>
    <div>Back</div>
    <div>Front</div>
  </div>
</div>

<footer>
  <p>Try it on your mobile device to handle the cube! (not working in Safari)<br>Coded by <a href="https://webdeasy.de/?referer=cp-oRKdwM" target="_blank">WebDEasy</a></p>
</footer>
* {
  margin: 0;
  padding: 0;
}
.wrapper {
  height: 250px;
  perspective: 700px;
  -webkit-perspective: 700px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  font-family: arial, sans-serif;
}

.cube {
  width: 100px;
  height: 100px;
  transform-style:preserve-3d;
  transform:rotateY(35deg) rotatex(50deg);
}

.cube > div {
  position: absolute;
  width: 120px;
  height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #FFF;
  text-transform: uppercase;
}

.cube div:nth-child(1){
  transform:translateZ(60px);
  background:#237ad4;
}

.cube div:nth-child(2){
  transform: rotateX(180deg) translateZ(60px);
  background:#2070c3;
}

.cube div:nth-child(3){
  transform: rotateY(-90deg) translateZ(60px);
  background:#2e84dd;
}

.cube div:nth-child(4){
  transform:rotateY(90deg) translateZ(60px);
  background:#3f8edf;
}

.cube div:nth-child(5){
  transform: rotateX(90deg) translateZ(60px);
  background:#2070d3;
}

.cube div:nth-child(6){
  transform:rotateX(-90deg) translateZ(60px);
  background:#1d67b2;
}

footer {
  text-align: center;
  width: calc(100% - 4rem);
  background-color: #237ad4;
  color: #FFF;
  position: absolute;
  bottom: 0;
  font-size: 12px;
  padding: 0 2rem;
}

footer p {
  font-family: arial, sans-serif;
  padding: .8rem 0;
  line-height: 20px;
}

footer a {
  background-color: rgba(255, 255, 255, .6);
  padding: 5px 10px;
  text-decoration: none;
  color: #237ad4;
}
window.addEventListener("deviceorientation", (e) => {
  const beta = e.beta;
  const gamma = e.gamma;
  
  // disable for desktop devices
  if(beta == null || gamma == null) {
    return false;  
  }
  
  document.getElementsByClassName('cube')[0].style.transform = 'rotateY(' + gamma*3 + 'deg) rotateX(' + beta*3 +'deg)';
}, true);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.