Skip to content
IndexRequest a UIAboutContact

Streaming Chat Response

An assistant reply that streams in word by word with a caret, a Stop button and a clear finished state.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a chat card 320x220px with a scrolling message area and a composer (text input and a 40px round send button). Pressing Enter or the button adds the user's message as a right-aligned dark bubble (fade and rise 6px in 180ms) and starts a simulated assistant reply as a left-aligned light bubble. Stream a prepared paragraph word by word every 45ms with a thin blinking caret at the end; set aria-busy true on the message list while streaming and, when finished, remove the caret and announce "Response complete" in a visually hidden live region. While streaming the send button becomes a Stop button (square icon, aria-label "Stop generating"); pressing it ends the stream and appends a small "Stopped" label. Disable sending while streaming. Auto-scroll to the bottom unless the user scrolled up. Under prefers-reduced-motion show the full answer after 300ms with no caret blink.

About this pattern

Definition

A chat exchange where the answer appears progressively as it is generated, instead of after a long wait. A Stop control lets the user cancel, and the interface clearly shows when the answer is complete.

Purpose & UX principles

  • Streaming makes waiting feel shorter and lets people start reading early.
  • A Stop button gives control; the Send button turns into Stop while generating and back afterwards.
  • Screen readers should not hear every token: the message region is marked busy while streaming and the full answer is announced once at the end.

Interaction states

  • Idle, sending (user bubble appears), streaming (caret, Stop), stopped (note "Stopped"), complete.

Motion specification

  • Words arrive every 45ms; the caret blinks at 1s intervals; new bubbles fade and rise 6px in 180ms.
  • Reduced motion: the whole answer appears at once after a short pause and the caret does not blink.

Responsive behaviour

  • The message list scrolls and keeps the latest text in view unless the user scrolled up on purpose.
  • The composer is a single row with a 44px button on touch.

Code

HTML
<div class="chat"><div class="msgs" id="msgs" aria-live="off" role="log" aria-label="Conversation"></div>
<form class="comp" id="f"><input id="in" type="text" placeholder="Ask anything…" aria-label="Message" autocomplete="off"><button id="go" aria-label="Send">↑</button></form><span class="sr" id="sr" aria-live="polite"></span></div>

Related patterns

Agent Steps Timeline

↗
Agent Steps TimelineAI & Conversational

Skeleton Loading

↗
Skeleton LoadingLoading & Progress

Toast

↗
ToastFeedback & Notifications