Text types itself out one character at a time behind a blinking caret. Pure CSS: the width steps up one character per frame using ch units, so set the step count to your text's length.
Also known as: typing animation, typing text effect, terminal typing.
<div class="txt-typewriter">Hello, world.</div>
.txt-typewriter {
--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-block;
overflow: hidden;
white-space: nowrap;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
color: var(--c);
border-right: 0.08em solid var(--c);
width: 0;
/* 13 = number of characters in the text */
animation: txt-typewriter-type 1.6s steps(13) forwards, txt-typewriter-caret 0.8s step-end infinite;}
@keyframes txt-typewriter-type {
to { width: 13ch; }
}
@keyframes txt-typewriter-caret {
50% { border-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
.txt-typewriter, .txt-typewriter *, .txt-typewriter::before, .txt-typewriter::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.