Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why setting `overflow` to both on html and body?

I just noticed that many css plugins, when setting the page overflow to hidden (for example), they use to set it both to html and body, like this:

html, body {
    overflow: hidden;
}

For example, fullpage.js does like this.

What is the exact difference between setting it to the body and the html?
Is it a cross-browser trick?

like image 935
ProGM Avatar asked Nov 28 '25 21:11

ProGM


1 Answers

This is a CSS trick to prevent unwanted scroll bars, particularly horizontal bars. What it prevents is anything wider than the html or body being displayed therefore preventing the scrollbars. Here is an indepths csstricks article: https://css-tricks.com/findingfixing-unintended-body-overflow/

However you will notice right at the end, he mentions that putting the overflow hidden on the body (and html) is not recommended.

In the case of fullpage.js, it is fine because they specifically trying to hide the scroll bars so that their animations can bring in the content that is off screen.

like image 95
Tim Lewis Avatar answered Dec 01 '25 11:12

Tim Lewis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!