A typewriter for proportional fonts: each letter is a span that appears on its own beat, and the caret rides on whichever letter was typed last. Shown here as a serif pull quote.
Also known as: typewriter effect proportional font, letter by letter typing css, typing animation without monospace.
<blockquote class="txt-typewriter-any-font" aria-label="Less, but better."> <span class="txt-typewriter-any-font-t" aria-hidden="true"><span style="--i: 0">L</span><span style="--i: 1">e</span><span style="--i: 2">s</span><span style="--i: 3">s</span><span style="--i: 4">,</span><span style="--i: 5"> </span><span style="--i: 6">b</span><span style="--i: 7">u</span><span style="--i: 8">t</span><span style="--i: 9"> </span><span style="--i: 10">b</span><span style="--i: 11">e</span><span style="--i: 12">t</span><span style="--i: 13">t</span><span style="--i: 14">e</span><span style="--i: 15">r</span><span style="--i: 16">.</span></span> </blockquote>
.txt-typewriter-any-font {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
position: relative;
margin: 0;
padding-left: 0.2em;
font-family: ui-serif, Georgia, "Times New Roman", serif;
font-style: italic;
font-weight: 400;}
.txt-typewriter-any-font::before {
content: "“";
position: absolute;
left: -0.4em;
top: -0.2em;
font-size: 2em;
font-style: normal;
line-height: 1;
color: var(--c);
}
/* caret before the first key */
.txt-typewriter-any-font-t::before {
content: "";
display: inline-block;
width: 0.06em;
height: 0.9em;
margin-right: -0.06em;
vertical-align: -0.1em;
background: var(--c);
animation: txt-typewriter-any-font-gone 0s 0.4s forwards;
}
.txt-typewriter-any-font-t span {
position: relative;
opacity: 0;
animation: txt-typewriter-any-font-key 0s calc(0.4s + var(--i) * 80ms) forwards;
}
/* each letter owns the caret for one beat */
.txt-typewriter-any-font-t span::after {
content: "";
position: absolute;
top: 0.15em;
bottom: 0.05em;
right: -0.05em;
width: 0.06em;
background: var(--c);
opacity: 0;
animation: txt-typewriter-any-font-caret 80ms step-end calc(0.4s + var(--i) * 80ms);
}
.txt-typewriter-any-font-t span:last-child::after {
animation: txt-typewriter-any-font-blink 1s step-end calc(0.4s + var(--i) * 80ms) infinite;
}
@keyframes txt-typewriter-any-font-gone {
to { visibility: hidden; }
}
@keyframes txt-typewriter-any-font-key {
to { opacity: 1; }
}
@keyframes txt-typewriter-any-font-caret {
0%, 100% { opacity: 1; }
}
@keyframes txt-typewriter-any-font-blink {
0% { opacity: 1; }
50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.txt-typewriter-any-font, .txt-typewriter-any-font *, .txt-typewriter-any-font::before, .txt-typewriter-any-font::after, .txt-typewriter-any-font *::before, .txt-typewriter-any-font *::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.