Two words sit on the faces of a 3D box that rolls a quarter turn upward, holds, then rolls again with a springy settle. Four faces placed with rotateX and translateZ inside a preserve-3d box.
Also known as: rotating cube text css, 3d cube words, text on cube faces.
<div class="txt-3d-text-cube" aria-label="Dream, build"><div class="txt-3d-text-cube-box" aria-hidden="true"><span style="--f: 0">DREAM</span><span style="--f: 1">BUILD</span><span style="--f: 2">DREAM</span><span style="--f: 3">BUILD</span></div></div>
.txt-3d-text-cube {
--c: var(--txt-color, #3b82f6);
font-size: calc(var(--txt-size, 32px) * 1.15);
font-family: system-ui, sans-serif;
font-weight: 800;
line-height: 1.2;
display: inline-block;
perspective: 10em;
letter-spacing: 0.08em;}
.txt-3d-text-cube-box {
display: grid;
transform-style: preserve-3d;
animation: txt-3d-text-cube-roll 8s cubic-bezier(0.5, -0.3, 0.3, 1.35) infinite;
}
.txt-3d-text-cube-box span {
grid-area: 1 / 1;
height: 1.5em;
padding: 0 0.6em;
line-height: 1.5em;
text-align: center;
color: #fff;
background: var(--c);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
/* face f sits f quarter turns around the X axis, half the height out */
transform: rotateX(calc(var(--f) * -90deg)) translateZ(0.75em);
}
.txt-3d-text-cube-box span:nth-child(even) {
background: color-mix(in srgb, var(--c) 72%, #000);
}
@keyframes txt-3d-text-cube-roll {
0%, 20% { transform: rotateX(-18deg) rotateX(0deg); }
25%, 45% { transform: rotateX(-18deg) rotateX(90deg); }
50%, 70% { transform: rotateX(-18deg) rotateX(180deg); }
75%, 95% { transform: rotateX(-18deg) rotateX(270deg); }
100% { transform: rotateX(-18deg) rotateX(360deg); }
}
@media (prefers-reduced-motion: reduce) {
.txt-3d-text-cube, .txt-3d-text-cube *, .txt-3d-text-cube::before, .txt-3d-text-cube::after, .txt-3d-text-cube *::before, .txt-3d-text-cube *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.