AI CSS Animations

Block Swipe Reveal

A solid bar in the accent color sweeps across, and the text is there when it passes. Two animations: the bar scales in from the left then out to the right, and the text appears mid-sweep.

Also known as: colored block reveal, swipe reveal text, bar reveal.

Chapter one

HTML

<div class="txt-curtain-reveal">Chapter one</div>

CSS

.txt-curtain-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;
  padding: 0 0.15em;
  color: var(--c);
  opacity: 0;
  animation: txt-curtain-reveal-show 0.01s linear 0.45s forwards;}
.txt-curtain-reveal::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: left;
  animation: txt-curtain-reveal-sweep 0.9s cubic-bezier(0.7, 0, 0.3, 1) forwards;
}
@keyframes txt-curtain-reveal-show {
  to { opacity: 1; }
}
@keyframes txt-curtain-reveal-sweep {
  0%   { transform: scaleX(0); transform-origin: left; }
  50%  { transform: scaleX(1); transform-origin: left; }
  51%  { transform: scaleX(1); transform-origin: right; }
  100% { transform: scaleX(0); transform-origin: right; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-curtain-reveal, .txt-curtain-reveal *, .txt-curtain-reveal::before, .txt-curtain-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