AI CSS Animations

Split Text Reveal Effect

The top half of the word slides in from the left and the bottom half from the right, meeting in the middle. Two clipped pseudo-element copies, then the real text takes over.

Also known as: split text animation css, two halves text effect, sliced text reveal.

Meet halfway

HTML

<div class="txt-split-text-reveal" data-text="Meet halfway">Meet halfway</div>

CSS

.txt-split-text-reveal {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  position: relative;
  display: inline-block;
  white-space: nowrap;
  color: transparent;
  animation: txt-split-text-reveal-settle 0s 1s forwards;}
/* the halves are copies; the empty alt text keeps screen readers from reading them */
.txt-split-text-reveal::before,
.txt-split-text-reveal::after {
  content: attr(data-text);
  content: attr(data-text) / "";
  position: absolute;
  inset: 0;
  color: var(--c);
}
.txt-split-text-reveal::before {
  clip-path: inset(0 0 50% 0);
  animation: txt-split-text-reveal-left 1s cubic-bezier(0.7, 0, 0.2, 1) both, txt-split-text-reveal-hide 0s 1s forwards;
}
.txt-split-text-reveal::after {
  clip-path: inset(50% 0 0 0);
  animation: txt-split-text-reveal-right 1s cubic-bezier(0.7, 0, 0.2, 1) both, txt-split-text-reveal-hide 0s 1s forwards;
}
@keyframes txt-split-text-reveal-left {
  0%   { opacity: 0; transform: translateX(-1.6em); }
  35%  { opacity: 1; }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes txt-split-text-reveal-right {
  0%   { opacity: 0; transform: translateX(1.6em); }
  35%  { opacity: 1; }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes txt-split-text-reveal-hide {
  to { visibility: hidden; }
}
@keyframes txt-split-text-reveal-settle {
  to { color: var(--c); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-split-text-reveal, .txt-split-text-reveal *, .txt-split-text-reveal::before, .txt-split-text-reveal::after, .txt-split-text-reveal *::before, .txt-split-text-reveal *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations