A title card tilts slowly in 3D while its eyebrow, headline and tagline float at different depths, so they slide past each other in parallax. Each line sits at its own translateZ inside the card.
Also known as: parallax text effect css, 3d tilt card text, layered depth title.
<div class="txt-parallax-title-card">
<div class="txt-parallax-title-card-pitch">
<div class="txt-parallax-title-card-card">
<span class="txt-parallax-title-card-eyebrow">Season two</span>
<span class="txt-parallax-title-card-title">PARALLAX</span>
<span class="txt-parallax-title-card-tagline">every layer at its own depth</span>
</div>
</div>
</div>.txt-parallax-title-card {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
display: inline-block;
perspective: 12em;}
.txt-parallax-title-card-pitch,
.txt-parallax-title-card-card {
transform-style: preserve-3d;
}
.txt-parallax-title-card-pitch {
animation: txt-parallax-title-card-pitch 3.2s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
/* two rotations on different clocks trace a slow, looping figure eight */
.txt-parallax-title-card-card {
display: grid;
justify-items: center;
gap: 0.4em;
padding: 0.65em 1.1em 0.75em;
border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
border-radius: 0.35em;
background: color-mix(in srgb, var(--c) 8%, transparent);
animation: txt-parallax-title-card-yaw 4.8s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
.txt-parallax-title-card-eyebrow {
font-size: 0.42em;
font-weight: 600;
letter-spacing: 0.3em;
text-transform: uppercase;
color: color-mix(in srgb, var(--c) 75%, transparent);
transform: translateZ(1.05em); /* 0.45 of the card's em */
}
.txt-parallax-title-card-title {
font-size: 1.5em;
font-weight: 900;
line-height: 1;
color: var(--c);
text-shadow: 0 0.08em 0.16em color-mix(in srgb, var(--c) 25%, transparent);
transform: translateZ(0.54em); /* 0.8 of the card's em */
}
.txt-parallax-title-card-tagline {
font-size: 0.4em;
font-weight: 500;
color: color-mix(in srgb, var(--c) 70%, transparent);
transform: translateZ(0.62em); /* 0.25 of the card's em */
}
@keyframes txt-parallax-title-card-pitch {
from { transform: rotateX(12deg); }
to { transform: rotateX(-12deg); }
}
@keyframes txt-parallax-title-card-yaw {
from { transform: rotateY(-18deg); }
to { transform: rotateY(18deg); }
}
@media (prefers-reduced-motion: reduce) {
.txt-parallax-title-card, .txt-parallax-title-card *, .txt-parallax-title-card::before, .txt-parallax-title-card::after, .txt-parallax-title-card *::before, .txt-parallax-title-card *::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.