JSFiddle - React, Tailwind, and code Playground
HTML
<div class="cube">
<div class="face front">front</div>
<div class="face back">back</div>
<div class="face left">left</div>
<div class="face right">right</div>
<div class="face top">top</div>
<div class="face bottom">bottom</div>
</div>
CSS
body {
/* Set the size of the sides of the cube here */
--S: 150px;
}
/* Common properties for all faces: position absolute and size */
.face {
position: absolute;
width: var(--S);
height: var(--S);
}
.cube {
transform-style: preserve-3d;
/* transform-origin: center center; */
width: var(--S);
height: var(--S);
}
.face.front { transform: translateZ(calc(var(--S) / 2)); }
.face.back { transform: rotateY(180deg) translateZ(calc(var(--S) / 2)); }
.face.left { transform: rotateY(-90deg) translateZ(calc(var(--S) / 2)); }
.face.right { transform: rotateY(90deg) translateZ(calc(var(--S) / 2)); }
.face.top { transform: rotateX(90deg) translateZ(calc(var(--S) / 2)); }
.face.bottom { transform: rotateX(-90deg) translateZ(calc(var(--S) / 2)); }
/* Colors and text position */
.face { line-height: var(--S); text-align: center; color: white; font-size: calc(var(--S) / 4); }
.front { background-color: rgba(255, 0, 0, 0.5); }
.back { background-color: rgba(0, 255, 0, 0.5); }
.left { background-color: rgba(0, 0, 255, 0.5); }
.right { background-color: rgba(0, 255, 255, 0.5); }
.top { background-color: rgba(255, 0, 255, 0.5); }
.bottom { background-color: rgba(255, 255, 0, 0.5); }
/* Rotate a bit to show something 3D */
.cube { transform: rotateY(30deg) rotateX(30deg); }
.cube { border: solid 1px black; }
.cube { margin: 50px auto 0 auto; }