AI CSS Animations

Highlighter Sweep

A translucent highlighter stroke draws in behind the words after a short delay, as if someone marked the important line. Plays once, then stays.

Also known as: marker highlight text, text underline highlight.

The part that matters

HTML

<div class="txt-highlight-sweep">The part that matters</div>

CSS

.txt-highlight-sweep {
  --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;
  background: linear-gradient(color-mix(in srgb, var(--c) 45%, transparent), color-mix(in srgb, var(--c) 45%, transparent)) no-repeat 0 85%;
  background-size: 0% 40%;
  animation: txt-highlight-sweep-draw 0.8s ease-out 0.4s forwards;}
@keyframes txt-highlight-sweep-draw {
  to { background-size: 100% 40%; }
}

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