Code Snippet

Home » Code Snippets » CSS » Force Vertical Scrollbar

Force Vertical Scrollbar

html {
       overflow-y: scroll;
}

This is invalid CSS, but it works in everything except Opera. The reason for this is to prevent "centering jumps" when navigating back and forth between pages with enough content to have a vertical scroll bar and pages that do not.

Subscribe to The Thread

  1. There’s a specific one for Mozilla: overflow: -moz-scrollbars-vertical;

    IE I think always shows the vert scroll bars

  2. Hi there I like this new snippets area very useful !

  3. Thanks for the visit and the kind comment.have a wonderful day

  4. Holger

    It works perfectly in Opera 11.01. Thanks for the tip!

    PS: You have an awesome form.

  5. This is great, but it creates a double scrollbar, doesn’t it?

  6. Thanks, works a treat :)

    W00t!

  7. what about

    height: 101% ?

    this was an an advice published in the blog of a CSS professional.
    i dont have the link, but you can seach in google for this code.

  8. Chris; An inelegant solution. overflow-y:scroll; adds a disabled scrollbar if the page height or content size is less than, or becomes less than the browser size. height:101%; (and other similar solutions, like margin: 0,0,1px;) enable that scrollbar and lets the user scroll a few pixels. It may seem moot, but I like my scrollbars disabled when there’s no need to use them for scrolling purposes.

  9. Thank you!

    If this is invalid, someone should rethink what is valid again.

  10. What do You think about this snippet:

    html { min-height: 100%; padding-bottom: 1px; }
  11. I’m using this to force the scroll bar:

    html {heigth: 100%; margin-bottom: 1px}

    Quite similar to Phillips solution.

  12. This works great for sites that use jQuery and slide up and down. I used it on my final for a JavaScripting class. It keeps the bar there so when the page changes from one with lots of content to one with little content the whole page doesn’t shift to the left or right.

    Thanks.

    Here’s an example that might help more than my explanation… :P

    http://tymayn.com/school/jsFinal/

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~