Difference between HTML "overflow : auto" and "overflow : scroll"

HtmlCss

Html Problem Overview


When I was studying the overflow property's values, I came across these two values: auto and scroll, which adds scrollbar(s) if the content overflows the element.

Could someone please explain me whats the difference between them?

Html Solutions


Solution 1 - Html

Auto will only show a scrollbar when any content is clipped.

Scroll will however always show the scrollbar even if all content fits and you cant scroll it.

Solution 2 - Html

overflow: scroll will hide all overflowing content and cause scroll bars to appear on the element in question. If the content does not overflow, the scrollbars will still be visible, but disabled.

overflow: auto is very similar, but the scrollbars only appear when the content is overflowing.

There is a similar explanation of this here, with some screenshots to illustrate the point.

Solution 3 - Html

Take a look at CSS Tricks.

Auto will show scrollbar if and only if the content overflows; but scroll will always show the scrollbar, whether the content is overflowing or not.

Solution 4 - Html

Adding a point to the answer, Overflow:auto not worked in IE7 when position of the container is absolute Position relative overflow IE7. But setting Overflow:scroll works

Solution 5 - Html

overflow: scroll will show both horizontal and vertical scrollbar even when you don't need one or other. while, overflow: auto will show the scrollbar which your div needs. so basically auto will help you to get rid of both scollbar. Here is more of that:

https://css-tricks.com/the-css-overflow-property/

Solution 6 - Html

In Windows, overflow: scroll will always show the scrollbar and overflow: auto will show the scrollbar only if the content is overflowing. In macOS, the overflow: scroll and overflow: auto will always show the scrollbar if the content is overflowing. Tested in Chrome. I highly recommend using overflow: auto as it works the same way and does not generate problems in windows

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGirishKView Question on Stackoverflow
Solution 1 - HtmlJohan DavidssonView Answer on Stackoverflow
Solution 2 - HtmlJames AllardiceView Answer on Stackoverflow
Solution 3 - Htmlsamir chauhanView Answer on Stackoverflow
Solution 4 - HtmlKiraView Answer on Stackoverflow
Solution 5 - Htmlmanish joshiView Answer on Stackoverflow
Solution 6 - HtmlDiego Fernando CastroView Answer on Stackoverflow