An AI answer streams in word by word, each word resolving from a soft accent glow, with a pulsing dot at the end of the stream that fades once the reply is complete.
Also known as: chatgpt typing effect, ai response text animation, llm token streaming css.
Sure! Here's a quick plan for three days in Kyoto.
<p class="txt-ai-streaming-text"><span style="--i: 0">Sure!</span> <span style="--i: 1">Here's</span> <span style="--i: 2">a</span> <span style="--i: 3">quick</span> <span style="--i: 4">plan</span> <span style="--i: 5">for</span> <span style="--i: 6">three</span> <span style="--i: 7">days</span> <span style="--i: 8">in</span> <span style="--i: 9">Kyoto.</span></p>
.txt-ai-streaming-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;
max-width: 11em;
margin: 0;
font-size: calc(var(--txt-size, 32px) * 0.8);
font-weight: 500;
line-height: 1.4;
text-align: left;}
.txt-ai-streaming-text span {
position: relative;
animation: txt-ai-streaming-text-in 0.35s ease-out calc(0.3s + var(--i) * 0.14s) both;
}
/* the dot rides on the newest word */
.txt-ai-streaming-text span::after {
content: "";
position: absolute;
top: 0.5em;
right: -0.7em;
width: 0.42em;
height: 0.42em;
border-radius: 50%;
background: var(--c);
opacity: 0;
animation: txt-ai-streaming-text-dot 0.14s step-end calc(0.5s + var(--i) * 0.14s);
}
.txt-ai-streaming-text span:last-child::after {
animation: txt-ai-streaming-text-done 1.4s ease-in-out calc(0.5s + var(--i) * 0.14s) forwards;
}
@keyframes txt-ai-streaming-text-in {
0% { color: transparent; text-shadow: 0 0 0.3em transparent; }
35% { color: transparent; text-shadow: 0 0 0.25em color-mix(in srgb, var(--c) 75%, transparent); }
}
@keyframes txt-ai-streaming-text-dot {
0%, 100% { opacity: 1; }
}
@keyframes txt-ai-streaming-text-done {
0% { opacity: 1; transform: scale(1); }
30% { transform: scale(0.6); }
60%, 80% { opacity: 1; transform: scale(1); }
100% { opacity: 0; transform: scale(0.3); }
}
@media (prefers-reduced-motion: reduce) {
.txt-ai-streaming-text, .txt-ai-streaming-text *, .txt-ai-streaming-text::before, .txt-ai-streaming-text::after, .txt-ai-streaming-text *::before, .txt-ai-streaming-text *::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.