<input type="radio" name="rotateAxis" class="hidden" id="axesX">
<input type="radio" name="rotateAxis" class="hidden" id="axesY">
<input type="radio" name="rotateAxis" class="hidden" id="axesZ" checked>

<input type="checkbox" class="hidden" id="usePerspective">

<div class="container">
  <div class="square"></div>
</div>

<div class="options">

  <h3>Rotate on:</h3>
  <label for="axesX" class="axis axesX">X axis</label>
  <label for="axesY" class="axis axesY">Y axis</label>
  <label for="axesZ" class="axis axesZ">Z axis</label>

  <label for="usePerspective" class="usePerspective">Use perspective</label>
</div>
@import url("https://fonts.googleapis.com/css2?family=Anton&display=swap");

*, *::before, *::after {
  padding: 0;
  margin: 0 auto;
  box-sizing: border-box;
}

body {
  font-family: 'Anton', sans-serif;
  background-color: #eee;
  color: #333;
  min-height: 100vh;
  display: -webkit-box;
  display: flex;
  -webkit-box-pack: center;
          justify-content: center;
  align-content: center;
  -webkit-box-align: center;
          align-items: center;
  flex-wrap: wrap;
}

.hidden {
  position: fixed;
  top: -10000px;
  left: -10000px;
  visibility: hidden;
}

.container {
  width: 200px;
  height: 200px;
  border: 1px solid #fff;
  border-radius: 4px;
  display: -webkit-box;
  display: flex;
  -webkit-box-align: center;
          align-items: center;
  margin: 1em;
}

.square {
  width: 100px;
  height: 100px;
  background-color: green;
}

.options {
  margin: 1em;
}

label.axis {
  display: inline-block;
  padding: 0.5em 1em;
  border: 1px solid #777;
  border-radius: 4px;
}

#axesX:checked ~ .container > .square {
  -webkit-animation: rotateOnX 4s infinite linear;
          animation: rotateOnX 4s infinite linear;
}

#axesX:checked ~ .options > label.axesX {
  background-color: greenyellow;
}

@-webkit-keyframes rotateOnX {
  to {
    -webkit-transform: rotateX(360deg);
            transform: rotateX(360deg);
  }
}

@keyframes rotateOnX {
  to {
    -webkit-transform: rotateX(360deg);
            transform: rotateX(360deg);
  }
}

#axesY:checked ~ .container > .square {
  -webkit-animation: rotateOnY 4s infinite linear;
          animation: rotateOnY 4s infinite linear;
}

#axesY:checked ~ .options > label.axesY {
  background-color: greenyellow;
}

@-webkit-keyframes rotateOnY {
  to {
    -webkit-transform: rotateY(360deg);
            transform: rotateY(360deg);
  }
}

@keyframes rotateOnY {
  to {
    -webkit-transform: rotateY(360deg);
            transform: rotateY(360deg);
  }
}

#axesZ:checked ~ .container > .square {
  -webkit-animation: rotateOnZ 4s infinite linear;
          animation: rotateOnZ 4s infinite linear;
}

#axesZ:checked ~ .options > label.axesZ {
  background-color: greenyellow;
}

@-webkit-keyframes rotateOnZ {
  to {
    -webkit-transform: rotateZ(360deg);
            transform: rotateZ(360deg);
  }
}

@keyframes rotateOnZ {
  to {
    -webkit-transform: rotateZ(360deg);
            transform: rotateZ(360deg);
  }
}

label.usePerspective {
  display: block;
  text-align: center;
  padding: 0.5em 1em;
  border: 1px solid #777;
  border-radius: 4px;
  margin-top: 1.5em;
}

#usePerspective:checked ~ .container {
  -webkit-perspective: 240px;
          perspective: 240px;
}

#usePerspective:checked ~ .options label.usePerspective {
  background-color: greenyellow;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.