Page Shift Bothers Me

Have you ever been to a website where the pages shift when navigating from one page to another? The author of a particular site may have done an incredible job of designing a world-class theme, but the ocassional page shift can be a cause of irritation to some including myself. So, what causes page shifts? How do you get rid of it?

First of all, the cause. All browsers including the popular Mozilla’s Firefox and Microsoft’s Internet Explorer add a vertical scrollbar to webpages that do not fit the screen. A typical monitor screen usually has a resolution of 1028 x 768. Some screens have slightly lower resolution at 800 x 600 and a few at 1280 x 1024. The vertical resolution is the second number. So, a typical screen has a vertical resolution of 600, 768 and 1024 pixels.

No matter how big your screen size a great deal of web pages will exceed the vertical resolution of your screen. That’s a fact. For pages that either too long or too tall, all browsers add a vertical scroll bar to the page for navigation purposes. Users can either use the Page UP or Page Down keys, the Up and Down arrow keys, or the click-wheel which are available on the latest computer mouse for navigation purposes.

Now a few browsers such as Firefox are configured by default to hide the vertical scrollbar for pages that fits a user’s screen. The difference in width when the vertical scrollbar is on and off causes some webpages to shift left to right and vice versa. This especially true for webpages that are styled centrally. The page shifting is the cause of the irritation.

To eliminate the page shift, just add the following code to your CSS stylesheet. This code eliminates page shifting by forcing a vertical scrollbar to show up regardless of the height of the page whether it fits or exceeds the vertical resolution. The effect is you will always have a scrollbar present regardless of page height. It might look odd at first when you have a scrollbar that does not scroll, but people usually do not notice it. Chances are, they don’t even know.

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

For Firefox 3.5 or later, please add:

html { overflow: -moz-scrollbars-vertical !important; }

If you enjoyed this article, please share it with others using the social buttons below. If you like to be updated when a new article is published, please subscribe via email, RSS or follow me on Twitter: @ulyssesonline.

  • Twitter
  • Facebook
  • Delicious
  • Digg
  • StumbleUpon
  • Google
  • LinkedIn
  • Google Reader
  • FriendFeed
  • Reddit
  • Tumblr
  • Live
  • PDF
  • Email
  • RSS
  • Add to favorites

Random Posts

26 Comments

  • At 2006.03.26 12:58, ulyssesr said:

    Sure. I hope the CSS code worked out for you.

    • At 2007.08.05 02:00, Laurens said:

      Fantastic tip, which I fortunately found after only a day of wondering why pages shifted :-)
      I hadn’t even thought about the scroll bar.

      One little thing: a copy-paste of your code only worked after I deleted the space inbetween html and {

      • At 2008.11.02 12:39, Sasha said:

        Thank you so much for this! I had been sitting at my compuer for about 4 hours editing the coding and you have solved it in one go!

        • At 2009.01.25 00:06, Traci said:

          Thank you so much for posting this hint. I was beating my head against the wall and finally realized that the shift only happened with longer web pages. Once I typed in a query about this on google, your solution about the scroll bar came up and I tried it out. It worked like a charm.

          • At 2009.01.25 09:48, ulyssesr said:

            I’m glad I was able to help you. I wasn’t banging my head against the wall. I was pulling out my hair trying to figure out what’s causing the page shifts! :)

            • At 2009.04.14 20:25, Carl said:

              Dude – Thanks so much for the help! I spent an hour tweaking one page line by line, thinking that I had some error in my code. You saved me from throwing my keyboard against the wall!

              • At 2009.05.27 14:54, Richard said:

                Man – Seriously, kudos to this snippet. I thought I was going crazy.

                • At 2009.05.29 04:00, Mark Nielsen said:

                  This fix dosent work in IE8 and greater. so its a very time limited fix.

                  • At 2009.06.30 03:04, Bill said:

                    Every page but the index page shifts, please HELP!!!!! I cannot get it to stop, it does it in several browsers.

                    • At 2009.08.18 05:08, Jmoss said:

                      For those wondering why it’s not working on the newest Firefox 3.5 just add this line underneath the code above and voila:
                      html { overflow: -moz-scrollbars-vertical !important; }

                      • At 2009.08.18 15:01, ulyssesr said:

                        Jmoss. Super. I just validated it with Firefox 3.5. I’ll update the post. Thanks.

                        • At 2009.12.15 08:52, Tajinder Sarao said:

                          Work perfectly in Firefox !! Does anybody has fix for IE8?

                          • At 2009.12.15 10:16, ulyssesr said:

                            I did a little digging and found this article that seem to fix IE, but I haven’t tried it yet. Needs to be tested.

                            • At 2010.01.05 10:24, Nick said:

                              This doesnt fix the Firefox 3.5 issue. All it does is add TWO scrollbars.

                              • At 2010.01.05 18:31, ulyssesr said:

                                That is the fix.

                                • At 2010.05.10 03:49, Marc said:

                                  Thanks man – great tip.

                                  What I want to know is how to make a page like THIS ONE – you know where folks can add comments at the bottom of the page – like I'm doing…… what's the best way….free?

                                  • At 2010.05.10 12:08, ulyssesr said:

                                    Marc, A blog usually has a comment section after each post. I use WordPress blog software. You can download for free at wordpress.org. You can also sign up for a free blog at WordPress.com.

                                    • At 2010.05.12 03:14, Marc said:

                                      So I can integrate it into my current website on multiple pages….using my url..?

                                      • At 2010.05.12 20:22, ulyssesr said:

                                        Not exactly, but you can convert your current website into WordPress and automatically get a commenting feature.

                                        • At 2010.05.18 14:05, Awstoner said:

                                          THAAAAANNNNNNKKKKKK YOUUUUUUU!!!!

                                          • At 2010.07.13 05:52, Ajith Edassery said:

                                            Man,
                                            Thanks a ton. Just fixed it on my localhost and will be updating the blog with the it soon. This pageshift was bothering me for almost six-seven months now. It was looking really stupid when you move from page to page.

                                            Cheers and thanks again,
                                            Ajith

                                            • At 2010.07.13 18:23, Ulysses said:

                                              I’m glad that worked for you. Thanks for stopping by.

                                              • At 2010.11.16 08:58, Nny said:

                                                If this doesn’t work in your scenario try :

                                                html {height:101%;}

                                                • At 2011.08.17 08:34, Debra said:

                                                  THANK YOU!!! :) I’ve been racking my brain about this for a month. Site looks much better now and no shifting!!! I knew it was the scrollbar causing that but couldn’t get it fixed.

                                                  • At 2011.08.22 11:30, Ulysses said:

                                                    Yea I include this code on every page and project that I working on. Great stuff.

                                                    • 1 old comments are not displayed. Click to display all comments