Always show a vertical scrollbar in Firefox, Chrome, Safari and Opera
Posted June 20th, 2009 in HTML and CSS
Firefox, Chrome, Safari and Opera by default only show vertical scrollbars if the content on the page is longer than the window whereas Internet Explorer always shows vertical scrollbars. When moving from page to page where one is short and the next long it can make the layout jump around a bit so this post shows how to fix this for the other browsers.
The Solution
To save you having to scroll down and search for the answer I'll present it here first and then show some examples of what I'm talking about. This works in Firefox versions 1.5+ and for the current versions of the other browsers (I haven't tested the others in older versions).
html {
overflow-y: scroll;
}
Examples
This first screenshot shows a short page which doesn't require vertical scrollbars because the content doesn't go beyond the end of the window.

Now the content does go beyond the end of the the page so there is a vertical scrollbar. The flow of the text of the first paragraph is not the same as in the previous example because previously there wasn't one and now there is.

The final example has "html { overflow-y: scroll; }" set so the vertical scrollbar is always present. You can see this in the screenshot below where there is a scrollbar present but it's un-selectable.

Related posts:
- Disable textarea resizing for Safari and Chrome (Saturday, July 4th 2009)
- How to do a strikethrough with CSS (Saturday, June 13th 2009)
- Using CSS letter-spacing to space out titles (Saturday, April 18th 2009)
- Blockquotes and XHTML Strict (Saturday, April 11th 2009)
- Multiple CSS classes for a single element (Saturday, March 21st 2009)
- Force reload of updated CSS and Javascript files with unique filenames (Friday, March 20th 2009)
Subscribe / Follow / Email / Bookmark / Share
Use the buttons below to subscribe to my RSS feed to be notified next time something is posted, share this post with others, or subscribe by email to have my posts sent in a daily email, follow me on Twitter or follow me on Facebook.
At least one new post is usually made every day. See my posting schedule for more details.
