28

A lot of websites have this thing that if you scroll all the way up you get this "bounce" effect as if your page bounced off the top of your browser window revealing white space at the top of the window.

The same situation if you scroll down, you get the same exact "bounce" effect.

This bounce can look very ugly if your header and footer has a background colour.

How do i get rid of this effect?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

  <header></header>

  <div></div>

  <footer></footer>

</body>
</html>

CSS

header {
  width: 100%;
  background-color: tomato;
  height: 140px;
}

div {
  height: 1000px;
}

footer {
  width: 100%;
  background-color: brown;
  height: 140px;
}
Eli Himself
  • 834
  • 3
  • 8
  • 20
  • Does this answer your question? [Prevent "overscrolling" of web page](https://stackoverflow.com/questions/12046315/prevent-overscrolling-of-web-page) – cs95 Jun 19 '20 at 23:50

6 Answers6

48

I had similar issue this worked for me.

html {
    overflow: hidden;
    height: 100%;
}

body {
    overflow: auto;
    height: 100%;
}
Shrinivas Pai
  • 7,491
  • 4
  • 29
  • 56
28

So, the accepted answer doesn't work for me. I have to use https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior

So,

body {
    overscroll-behavior: none;
}
chug2k
  • 5,106
  • 2
  • 25
  • 30
Polv
  • 1,918
  • 1
  • 20
  • 31
1

It's better to use default bg

html,body{
     overscroll-behavior: auto;
     background: var(--color-bg-header);
}
Atul Kumar
  • 11
  • 1
0

Neither of the top answers worked for me by themselves, but when combined it worked fine.

html {
  overflow: hidden;
  height: 100%;
}

body {
  overflow: auto;
  height: 100%;
  overscroll-behavior: none;
}

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
-1

What ended up being best for me was adding style="overflow:hidden" directly on the <html> tag (via css didn't do it).

This of course prevents the page itself from moving on scroll, but in my case it's a web app where individual elements scroll independently within the page, so this is the effect I was looking for.

On mobile, I reverted back via overflow:auto !important in a media query.

timraybould
  • 681
  • 6
  • 9
-2

You can remove that effect by applying the following style:

body {
  height: 100%;
  width: 100%;
  overflow: auto;
}

This make the content only inside you body to be scroll-able.

Domain
  • 11,562
  • 3
  • 23
  • 44