The first word slides in from the left and the second from the right, they collide in the middle with a squash and a small spark, then bounce apart and settle. Two keyframes, mirrored.
Also known as: text slide in from left and right, words collide animation, split headline entrance.
<div class="txt-words-slide-together"><span class="txt-words-slide-together-a">Better</span> <span class="txt-words-slide-together-b">together</span></div>
.txt-words-slide-together {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
color: var(--c);
white-space: nowrap;}
.txt-words-slide-together-a,
.txt-words-slide-together-b {
display: inline-block;
}
.txt-words-slide-together-a {
transform-origin: 100% 50%;
animation: txt-words-slide-together-left 0.9s both;
}
.txt-words-slide-together-b {
position: relative;
transform-origin: 0 50%;
animation: txt-words-slide-together-right 0.9s both;
}
/* the spark in the gap at the moment of impact */
.txt-words-slide-together-b::before {
content: "";
position: absolute;
top: 0.12em;
bottom: 0.08em;
left: -0.16em;
width: 0.06em;
border-radius: 0.03em;
background: var(--c);
opacity: 0;
animation: txt-words-slide-together-spark 0.45s ease-out 0.42s both;
}
@keyframes txt-words-slide-together-left {
0% { opacity: 0; transform: translateX(-2.4em) scaleX(1); animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.5); }
20% { opacity: 1; }
48% { transform: translateX(0) scaleX(0.9); animation-timing-function: cubic-bezier(0.2, 0.8, 0.4, 1); }
68% { transform: translateX(-0.12em) scaleX(1.02); animation-timing-function: ease-in-out; }
100% { opacity: 1; transform: translateX(0) scaleX(1); }
}
@keyframes txt-words-slide-together-right {
0% { opacity: 0; transform: translateX(2.4em) scaleX(1); animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.5); }
20% { opacity: 1; }
48% { transform: translateX(0) scaleX(0.9); animation-timing-function: cubic-bezier(0.2, 0.8, 0.4, 1); }
68% { transform: translateX(0.12em) scaleX(1.02); animation-timing-function: ease-in-out; }
100% { opacity: 1; transform: translateX(0) scaleX(1); }
}
@keyframes txt-words-slide-together-spark {
0% { opacity: 1; transform: scaleY(0.3); }
30% { opacity: 1; transform: scaleY(1.5); }
100% { opacity: 0; transform: scaleY(1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-words-slide-together, .txt-words-slide-together *, .txt-words-slide-together::before, .txt-words-slide-together::after, .txt-words-slide-together *::before, .txt-words-slide-together *::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.