Back to Snippets

AI Thinking Indicator with Reasoning Panel JS

A reply that shows its reasoning while the model works. The label reads Thinking with a shimmer and a seconds counter, and the reasoning streams in word by word underneath. When the reasoning ends, the panel folds away, the label switches to a Thought for N seconds summary with the real elapsed time, and the answer streams in below it. Stop ends the reply early, and Ask again replays it.

The toggle is a button with aria-expanded and aria-controls, so screen readers know whether the reasoning is open. The panel opens and closes by animating grid-template-rows between 1fr and 0fr, which reaches the content's real height without measuring it. The panel folds away by itself only if the reader has not used the toggle, so someone who closed or reopened it keeps that choice. A hidden status region announces Thinking, the time taken and when the answer is ready.

The sample question asks whether 221 is prime, and the reasoning tests prime divisors up to 13, which is enough because 15 times 15 is already more than 221. To use a real model, append the reasoning and answer chunks it streams to the two paragraphs in place of streamWords. The shimmer and the folding animation turn off for visitors who prefer reduced motion.

0
#javascript
#css
#ai
#thinking indicator
#reasoning
#chatbot
#collapsible
#accessibility