Pattern Resilience Beginner
Thinking Indicator
Users are most likely to wonder whether anything happened in the pause between sending a prompt and the first token. A thinking indicator can fill that pause, as long as it appears right away, is announced to screen readers, respects reduced motion, and disappears as soon as real text arrives.
The problem
The user sends a prompt and, for a moment, nothing seems to happen. The model is loading context and working on its first token, but on screen the input box has emptied and the conversation looks the same as it did before. That pause is often a second or two, and much longer for models that reason before they respond, and during that pause, users might decide the request didn’t go through and send it again.
The pattern
As soon as the user sends a prompt, a thinking indicator appears in the assistant’s slot in the Message Thread, without waiting for a network response. It has its own look, such as animated dots or a pulsing avatar, so users can tell the assistant is working on a reply and don’t mistake it for a page-level spinner. Once the first token arrives through Streaming Response, the streamed content replaces the indicator, so the same message slot goes from thinking, to streaming, to complete.
Problem
If you do add feedback here, you might use the same generic spinner you use for a data fetch. A spinner tells the user that something is loading, but here the model is working on a reply, and the feedback should say that. Many of these indicators are also purely visual, so a screen reader user might send a prompt and hear nothing until a wall of text appears on the page.
The pause only lasts a moment, but it’s the first thing users see after they send a prompt, so if nothing seems to happen, the whole interface can feel unreliable before the reply has even started.
Solution
If you render the indicator inside a polite live region, with visually hidden text such as “Assistant is thinking…”, screen readers announce it, and users who can’t see the animation still know the assistant is working. AI responses almost always take long enough to need feedback, so you usually don’t need the short delay before showing the indicator that a normal Loading State uses. You do still need a static version for users who’ve set prefers-reduced-motion.
For agents that search or call tools before replying, the indicator can show the current phase, such as “Searching the docs…” or “Writing…”. Status text that changes as the work moves along tells users more than a spinner that could mean anything, because they can tell the agent is making progress and hasn’t got stuck.
Example
In each framework, the indicator is a status region with visually hidden text for screen readers, and three dots that screen readers skip.
The Indicator
function ThinkingIndicator({ label = 'Assistant is thinking' }) {
return (
<div className="thinking" role="status" aria-live="polite">
<span className="sr-only">{label}…</span>
<span className="dots" aria-hidden="true">
<span /><span /><span />
</span>
</div>
);
} <template>
<div class="thinking" role="status" aria-live="polite">
<span class="sr-only">{{ label }}…</span>
<span class="dots" aria-hidden="true"><span /><span /><span /></span>
</div>
</template>
<script setup>
defineProps({ label: { type: String, default: 'Assistant is thinking' } });
</script> <script>
let { label = 'Assistant is thinking' } = $props();
</script>
<div class="thinking" role="status" aria-live="polite">
<span class="sr-only">{label}…</span>
<span class="dots" aria-hidden="true"><span></span><span></span><span></span></span>
</div> class ThinkingIndicator extends HTMLElement {
connectedCallback() {
const label = this.getAttribute('label') || 'Assistant is thinking';
this.setAttribute('role', 'status');
this.setAttribute('aria-live', 'polite');
this.innerHTML = `
<span class="sr-only">${label}…</span>
<span class="dots" aria-hidden="true"><span></span><span></span><span></span></span>`;
}
}
customElements.define('thinking-indicator', ThinkingIndicator); Animated Dots, With a Reduced-Motion Fallback
The animation is only decoration, so users who’ve asked for reduced motion get a static indicator instead of pulsing dots.
.sr-only {
position: absolute; width: 1px; height: 1px;
padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%);
white-space: nowrap; border: 0;
}
.dots { display: inline-flex; gap: 0.25rem; }
.dots span {
width: 0.5rem; height: 0.5rem; border-radius: 50%;
background: currentColor; opacity: 0.4;
animation: blink 1.4s infinite both;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.4; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
.dots span { animation: none; opacity: 0.7; }
}
Swapping Thinking for Streamed Text
The indicator is just how an assistant message looks while it’s streaming and still has no content, so it disappears as soon as the first text arrives.
function AssistantMessage({ content, status }) {
// Empty + streaming = still thinking; any content = show the text
if (status === 'streaming' && content.length === 0) {
return <ThinkingIndicator />;
}
return <div className="content" aria-busy={status === 'streaming'}>{content}</div>;
}
Phase-Aware Status for Agents
If the model searches or calls tools before replying, the server can send an update for each phase, and the indicator shows a label for each one.
function AgentStatus({ phase }) {
// phase updates arrive from the server: 'thinking' | 'searching' | 'writing'
const label = {
thinking: 'Thinking',
searching: 'Searching the docs',
writing: 'Writing the answer',
}[phase] ?? 'Working';
return (
<div className="thinking" role="status" aria-live="polite">
<span className="sr-only">{label}…</span>
<span aria-hidden="true">
{label}
<span className="dots"><span /><span /><span /></span>
</span>
</div>
);
}
Benefits
- Users can tell something is happening during the pause before the first token, so they’re less likely to send the same prompt again.
- Users can tell that the assistant is working on a reply, which a generic loading spinner doesn’t tell them.
- With the indicator in a live region, screen reader users hear that the assistant is working, instead of hearing nothing until the reply appears.
- It’s just what a streaming message shows while it’s still empty, so it takes very little code to add if you’re already streaming responses.
- A status that names each phase shows progress while a long agent task runs, and that’s easier to put up with than a spinner that never changes.
Tradeoffs
- If the model takes a long time, an animated indicator with no real progress information can still make the app feel stuck, though phase labels can help.
- Screen readers can end up announcing both the thinking message and the streamed tokens, unless you’re careful about which live region announces what.
- Some screen readers don’t announce a live region that’s added to the page with its text already inside, and the examples here add it that way. It’s more reliable to keep an empty status region in the message slot from the start and change only the text inside it.
- If you make up phase labels, such as “Analyzing…” when nothing is being analyzed, users stop trusting them as soon as they notice.
- The animation needs a reduced-motion fallback, which is easy to forget, and without it, users who are sensitive to motion still get the animation.
- The page can flash when the first token replaces the indicator, unless the swap happens in the same message slot.
Summary
The pause between sending a prompt and the first token is often short, but if nothing appears during it, an AI interface can feel broken. A thinking indicator goes into the assistant’s message slot right away, is announced through a polite live region, stays static for reduced-motion users, and gets replaced by real tokens as they stream. For agents that search or call tools before replying, naming the current phase shows the user what’s happening.
See also
- Streaming Response — Resilience
- Message Thread — Components
- Loading State — Resilience
- Live Regions — Accessibility
- ARIA live regions - MDN
- prefers-reduced-motion - MDN
- Progress Indicators - NN Group