AI CSS Animations

Typing Test Text Effect

The whole sentence waits in faint gray while typed characters light up over it and the caret steps along, like a typing speed test, then the result slides in underneath.

Also known as: typing speed test animation, type racer text effect, typing practice animation.

HTML

<div class="txt-typing-test-text" aria-label="the quick brown fox. 92 words per minute, 100% accuracy">
  <span class="txt-typing-test-text-line" aria-hidden="true">
    <span class="txt-typing-test-text-ghost">the quick brown fox</span>
    <span class="txt-typing-test-text-typed">the quick brown fox</span>
    <span class="txt-typing-test-text-caret"></span>
  </span>
  <span class="txt-typing-test-text-stats" aria-hidden="true"><b>92</b> wpm <b>100%</b> acc</span>
</div>

CSS

.txt-typing-test-text {
  --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-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 500;}
.txt-typing-test-text-line {
  position: relative;
}
.txt-typing-test-text-ghost,
.txt-typing-test-text-typed {
  white-space: pre;
}
.txt-typing-test-text-ghost {
  color: color-mix(in srgb, currentColor 28%, transparent);
}
.txt-typing-test-text-typed {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  overflow: hidden;
  /* 19 characters at a brisk 65ms each */
  animation: txt-typing-test-text-type 1.24s steps(19) 0.5s forwards;
}
.txt-typing-test-text-caret {
  position: absolute;
  top: 0.12em;
  left: 0;
  width: 0.08em;
  height: 1em;
  border-radius: 0.04em;
  background: var(--c);
  animation:
    txt-typing-test-text-move 1.24s steps(19) 0.5s forwards,
    txt-typing-test-text-fade 0.5s ease-in-out 1.9s infinite alternate;
}
.txt-typing-test-text-stats {
  font-family: system-ui, sans-serif;
  font-size: 0.5em;
  color: color-mix(in srgb, currentColor 55%, transparent);
  animation: txt-typing-test-text-stats 0.4s ease-out 1.9s both;
}
.txt-typing-test-text-stats b {
  margin-left: 0.3em;
  font-size: 1.5em;
  color: var(--c);
}
.txt-typing-test-text-stats b:first-child {
  margin-left: 0;
}
@keyframes txt-typing-test-text-type {
  99.9%, to { width: 19ch; }
}
@keyframes txt-typing-test-text-move {
  99.9%, to { transform: translateX(19ch); }
}
@keyframes txt-typing-test-text-fade {
  0%, 40% { opacity: 1; }
  100% { opacity: 0.1; }
}
@keyframes txt-typing-test-text-stats {
  from { opacity: 0; transform: translateY(0.6em); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-typing-test-text, .txt-typing-test-text *, .txt-typing-test-text::before, .txt-typing-test-text::after, .txt-typing-test-text *::before, .txt-typing-test-text *::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