Twisting puzzle cube
Pure CSSA 3×3×3 cube built as three layers that take turns twisting a quarter turn. Each layer is one flat box with the stickers painted on by gradients.
Six faces placed with rotate + translateZ, spun by a single keyframe animation.
Your edited version
perspective on the parent. It is the camera distance — smaller means more dramatic.transform-style: preserve-3d, otherwise its children are flattened into its plane.translateZ by half the side length.--u, so the cube is the same share of a gallery card, the editor and a recording canvas. The side is 120 of those units.transform-style: preserve-3dperspective@keyframes:nth-child places each face<div class="scene">
<div class="cube">
<div>1</div><div>2</div><div>3</div>
<div>4</div><div>5</div><div>6</div>
</div>
</div>
.scene {
/* one base unit: every length below is a multiple of it, so the cube is the same share of a
card, the editor, a full screen and a recording canvas */
--u: 0.34vmin;
perspective: calc(800 * var(--u));
}
.cube {
--s: calc(120 * var(--u));
position: relative;
width: var(--s);
height: var(--s);
transform-style: preserve-3d;
animation: spin 9s linear infinite;
}
.cube > * {
position: absolute;
inset: 0;
display: grid;
place-items: center;
font: 700 calc(24 * var(--u)) Inter, system-ui;
background: rgb(139 108 255 / 0.28);
border: calc(1 * var(--u)) solid rgb(139 108 255 / 0.8);
}
/* turn each face outward, then push it half a side from the centre */
.cube > :nth-child(1) { transform: rotateY(0deg) translateZ(calc(var(--s) / 2)); }
.cube > :nth-child(2) { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.cube > :nth-child(3) { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.cube > :nth-child(4) { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.cube > :nth-child(5) { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.cube > :nth-child(6) { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
@keyframes spin {
from { transform: rotateX(-24deg) rotateY(0deg); }
to { transform: rotateX(-24deg) rotateY(360deg); }
}