Brad Frost

Fixed Positioning in Mobile Browsers

Fixed positioned elements (typically headers or footers) are extremely common conventions for native mobile platforms, so naturally fixed elements found their way into mobile browsers. Web designers are used to fixing elements to the window using CSS's position: fixed , however, in the land of mobile browsers, support for fixed positioning is far less universal and is way more quirky. I set up a demo to test fixed positioning support across mobile browsers. You can view the demo here. I was particularly curious to see how fixed positioning worked without disabling the user's ability to scale the page. The Test The actual test is as absurdly simple as you can get.

header { position: fixed; top: 0; left: 0; width: 100%; }

Talk about basic. Let's see how this is supported on mobile browsers. Mobile CSS Fixed Positioning Support

Maximiliano Firtman's amazing Mobile HTML5 site features a chart of fixed width mobile browser support, but (as you can see from the above results) "support" isn't exactly binary. Twitter's mobile site on iOS and AndroidTwitter's mobile site features a fixed header for iOS but not for Android Javascript Solutions Because mobile browsers lacked of CSS fixed positioning, some very smart people developed Javascript-based fixed-positioning solutions. Here are just some of the more popular ones:

Problem solved, right? Well, not exactly. Overriding the browser's default scrolling behavior introduces a whole lot of complexity, and that has implications. First, JS solutions definitely don't work across the board. Consider the vastly different results of the three lines of CSS in my test, and picture how a complex Javascript calculations might fare. Performance is key, and heavy JS usage can take it's toll when combined with the rest of the logic on the site/app. Also, the platforms that best support these solutions are also the ones that best support CSS fixed positioning (iOS5 being the poster child here). I'm going to pick on Paper.li's mobile site as a great example of what not to do. Their JS scrolling is clunky, entirely unnecessary and introduces a whole bunch of usability issues (i.e. I couldn't get to to Android's address bar because of the custom scrolling logic). In essence, they make it a whole lot harder to view their content. I recommend taking it on a case-by-case basis. I think JS solutions serve their purpose, but I don't know if sites deployed on the web is the best place for them. I think they make more sense for Phonegap projects or other projects where you have tighter control over device access. Considerations So what are you to do? Here's some things to think about as you approach this sticky situation (pun intended in the worst way possible):

Takeaway Ultimately, I think this little exercise is another example of why we need to consider diversity in our designs. Removing comfortable assumptions, even for something seemingly as harmless as a fixed header, can help us design better, more adaptive experiences. I believe that we can create great, innovative mobile experiences for best-of-breed devices without giving the middle finger to everything else.