# Your AI chat scrolls wrong. Fix it in 4 lines of CSS

DevFeed: [Your AI chat scrolls wrong. Fix it in 4 lines of CSS](<https://devfeed.tech/articles/your-ai-chat-scrolls-wrong-fix-it-in-4-lines-of-css-109899.md>)

Original publisher: [Read original article](<https://markodenic.tech/your-ai-chat-scrolls-wrong-fix-it-in-4-lines-of-css/>)

Author: Marko

Published: 2026-10-31T12:23:04Z

Content type: tutorial

Language: en

Sources: [Marko Denic Tech](<https://devfeed.tech/sources/marko-denic-tech.md>)

Topics: [CSS](<https://devfeed.tech/topics/css.md>), [AI Chat](<https://devfeed.tech/topics/ai-chat.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [User interface design](<https://devfeed.tech/topics/ui-design.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [blog-for-developers](<https://devfeed.tech/tags/blog-for-developers.md>), [browser-support](<https://devfeed.tech/tags/browser-support.md>), [build-faster](<https://devfeed.tech/tags/build-faster.md>), [chat](<https://devfeed.tech/tags/chat.md>), [code-productivity](<https://devfeed.tech/tags/code-productivity.md>), [code-smarter](<https://devfeed.tech/tags/code-smarter.md>), [content-monetization](<https://devfeed.tech/tags/content-monetization.md>), [css](<https://devfeed.tech/tags/css.md>), [css-animation](<https://devfeed.tech/tags/css-animation.md>), [css-performance](<https://devfeed.tech/tags/css-performance.md>), [developer-growth](<https://devfeed.tech/tags/developer-growth.md>), [developer-resources](<https://devfeed.tech/tags/developer-resources.md>), [email-newsletter-for-coders](<https://devfeed.tech/tags/email-newsletter-for-coders.md>), [front-end-development](<https://devfeed.tech/tags/front-end-development.md>), [github-profile-automation](<https://devfeed.tech/tags/github-profile-automation.md>), [html-tips](<https://devfeed.tech/tags/html-tips.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [javascript-tricks](<https://devfeed.tech/tags/javascript-tricks.md>), [learn-to-code](<https://devfeed.tech/tags/learn-to-code.md>), [responsive-design-tips](<https://devfeed.tech/tags/responsive-design-tips.md>), [streams](<https://devfeed.tech/tags/streams.md>), [ux](<https://devfeed.tech/tags/ux.md>), [web-dev-newsletter](<https://devfeed.tech/tags/web-dev-newsletter.md>), [web-development](<https://devfeed.tech/tags/web-development.md>), [web-development-tips](<https://devfeed.tech/tags/web-development-tips.md>), [weekly-dev-tips](<https://devfeed.tech/tags/weekly-dev-tips.md>), [workflow-optimization](<https://devfeed.tech/tags/workflow-optimization.md>)

## AI overview

For a streaming chat, a `column-reverse` scroll container can keep new text visible without forcing the user back to the bottom after they scroll up. The article puts messages inside a `.messages` wrapper, then styles the outer `.chat` with `display: flex`, `flex-direction: column-reverse`, `overflow-y: auto`, and `overscroll-behavior: contain`; it removes the per-update `scrollTop = scrollHeight` call. In this layout, the bottom is `scrollTop = 0`, scrolling upward produces negative values, and sending a new message can reset to zero. A wrapper preserves message order in both the DOM and display. The article says staying anchored while reading relies on browser scroll anchoring, which it reports works in Chrome, Edge, Firefox, and Safari 27; in older Safari, viewed text may drift as the answer streams. Short conversations start at the bottom.

## Source excerpt

Stop dragging users back to the bottom while the answer streams. Four lines of CSS make your chat follow new text, and stop the moment the user scrolls up.