Menu

CSS typing animation: a typewriter effect that survives any font, any length and line wraps
📰

CSS typing animation: a typewriter effect that survives any font, any length and line wraps

DEV Community: css·Crane Zhou·3 days ago
#tj8TstEh
#devtocss#devto#dev#cursor#article
Reading 0:00
15s threshold

For a single line in a monospace font, CSS can do this on its own: animate the element's width from zero to the length of the text in ch units, use steps() with the same number so it grows one character at a time, and let a right border be the cursor. Copy the first block below. If your font isn't monospace, the text needs to wrap, or someone else will be editing the words, skip to the per-letter version.

The copy-paste version

<p class = "typing" > Ship it before the coffee cools. </p>

Enter fullscreen mode

Exit fullscreen mode

.typing { width : 32ch ; /* characters in the line, spaces included */ white-space : nowrap ; overflow : hidden ; font-family : ui-monospace , Menlo , Consolas , monospace ; border-right : 0.1em solid ; /* the cursor */ animation : typing 3.2s steps ( 32 ) , blink 0.75s step-end 6 ; } @keyframes typing { from { width : 0 } } @keyframes blink { 50 % { border-color : transparent } }

@media ( prefers-reduced-motion : reduce ) { .typing { animation : none ; } }

Enter fullscreen…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.