StealThis .dev

CSS-only Typewriter

A typewriter animation using only CSS steps() timing function — no JavaScript, no libraries.

Open in Lab
css keyframes steps
Targets: HTML

Code

CSS-only Typewriter

A typewriter effect driven entirely by CSS steps() timing — zero JavaScript. The cursor blink is also CSS-only via a separate @keyframes on border-right.

How it works

The trick uses two animations running simultaneously on the text element:

  1. typing — animates width from 0 to 100% using steps(N) where N = character count. overflow: hidden clips the text as it types.
  2. blink — toggles border-right-color between the accent color and transparent for the cursor.
@keyframes typing { from { width: 0 } to { width: 100% } }
@keyframes blink  { 50% { border-right-color: transparent } }

Limitations

  • Works best with monospace fonts (character widths are equal)
  • The step count must match the character count exactly
  • Multi-line requires JS or separate elements per line

Variants

  • Add animation-iteration-count: infinite to loop
  • Chain multiple lines with animation-delay