Andi Smith

Thoughts on Implementing Responsive Design

"Responsive design" is the latest buzzword in a long series of web buzzwords which has featured "XML", "Web 2.0″ and "HTML5″ to name a few; but it's one that shouldn't be dismissed.

The days of assuming your user is browsing your website on a desktop or laptop machine are over. Mobile users are no longer restricted to people trying to find directions to a restaurant or building - they now sit at home on their comfy sofas and use their mobile phones to browse the web; they sit on trains and use their mobile data connections to shop online; they sit in parks whilst eating their lunch reading the latest news or tweets; or watching a TV catch up service. The human population are becoming slaves to their mobile phones as CNET's recent photo gallery showed.

Whether this is a good thing or a bad thing doesn't matter. It's now a fact of life. Netflix's recent comment about supporting almost 1,000 different Android devices using their service means that we cannot guarantee a certain screen resolution - unlike the iPhone, Android device screen sizes (and capabilities) vary immensely. And Androids are becoming more popular - we can't just ignore them.

But mobiles aren't the only device. Tablets are a whole new kind of device that have appeared in the last 3-4 years, with another set of screen resolutions. TVs and game consoles now ship with web browsers; and the desktop and laptop PC/Mac are far from dead either. The days of opening Photoshop, starting a new document; typing in a width and height and ignoring everything else are well and truly over.

Chris Coyer's recent slideshow "What We Don't Know" not only covered responsive design but a whole host of other user uncertainties and is well worth a read; but my favourite slide by far was the following one (even though it didn't include any mobile resolutions):

Screen resolutions

So how do we deal with this? Like everything in the world of web development, there is no one answer; and also it's messy. The usual story then!

The Responsive Design Checklist

Is Responsive Design the Right Choice?

It's easy to latch on to buzzwords but the truth is "Responsive Design" isn't the answer to every problem; just as "XML" was never the solution for every data problem, and not every website needs "HTML5″.

Responsive Design allows our sites to scale across multiple devices, but some solutions work better with a custom build for certain devices. Focusing on building a streamlined, specific solution for mobile or tablet can result in an experience optimised for these devices that doesn't feel forced.

Of course, you may decide that the right solution for your site is actually a hybrid of the two - a site which scales for different devices, yet key components are delivered differently depending on the device. This technique is known as Responsive Web Design with Server Side Components (RESS).

Luke Wroblewski has written a great post on these methods.

Types of Responsive

Luke Wroblewski has also recently written a excellent post on different types of responsive design. In it he lists five types of responsive design:

  • Mostly Fluid - a variation on fluid design which at large resolutions introduces margins; and at small resolutions stacks columns.
  • Column Drop - all content is in columns, and as the page width reduces, columns are dropped below one another.
  • Layout Shifter - using different layouts at different resolutions.
  • Tiny Tweaks - making subtle changes to the page as the resolution increases (such as text and image sizes).
  • Off Canvas - where columns are hidden off screen until the user requires them. Think of the Facebook user sidebar, which is hidden on mobile until the user presses a button.

More details of each are available on Luke's website - it really is a must-read for responsive design.

Your first decision when building a responsive design should be which of these categories your website falls in to.

Graceful Degradation vs Progressive Enhancement

There seem to be two camps of people - those that prefer "Graceful Degradation" and those that prefer "Progressive Enhancement".

"Graceful Degradation" means starting with a awesome base site which works on the latest browsers and technologies; and then adding fallbacks to support lesser capable browsers (it doesn't mean providing no fallback).

In terms of responsive design, this means building a site for larger resolutions and then gracefully degrading for smaller resolutions. At a very basic level, this would mean using media queries which use max-width. We can use media queries in our <link> element in our HTML when including our stylesheets, or in our CSS files.

A HTML Media Query:

<link rel="stylesheet" media="only screen and (max-width: 600px)"
href="styles.css" />

A CSS Media Query:

@media only screen and (max-width:600px) {
  // styles
}

Unless you are building a simple, single page application the tidier route is including separate stylesheets; although beware that the browser will download every stylesheet in case you resize the page while viewing the website.

"Progressive Enhancement" means starting with a basic base site that works on all browsers and then layering additional functionality on top for more capable browsers. Specifically for responsive design, this is also termed as "mobile first", and at a basic level would be media queries which use min- width.

There are lots of articles from different points of views on which is better - Designshack's article on "Mobile First Design: Why It’s Great and Why It Sucks" is a particularly good read.

Modernizr is an excellent tool for feature detection which can help with both graceful degradation and progressive enhancement.

Outside of responsive design, it does feel as though CSS naturally falls to graceful degradation - border radius' does not appear in older browsers for example. On the other hand, if you load all your images in the highest resolution, then your mobile users (who may be on their sofa, or may be on the train) are really going to suffer. Jason Grigsby has written some useful articles on responsive images.

Other Considerations

The Internet Explorer Factor

Once you've decided which method your responsive design will use, you need to work out how you are going to support it in Internet Explorer. Internet Explorer 9 only accepts a limited subset of media queries, which thankfully includes min-width and max-width (but not min-device-width and max-device- width); but earlier versions (of both desktop and mobile) will need to rely on conditional comments.

There is a conditional comment available for targeting mobile versions of Internet Explorer, so you may choose to use this to send it the stylesheet for smaller screen devices:

<!\--[if IEMobile]>
  <!\-- conditional content/styles here \-->
<![endif]\-->

Performance

As the browser downloads every stylesheet regardless of device width, it's important that you keep your code as tidy as possible. It's also important that you ensure creating a responsive design is not adding significant weight to your page. Brad Frost summed it up in a recent blog post when he said that visitors do not care if your site is responsive, they just care that they can do what they came to do.

As usual, minification and gzipping can help here - but be careful not to include images, functionality and content that is no use for smaller screen devices.

Device Testing

It's impossible to test your design on every device that the user could possibly use, but it is important to get a representation of what your users will be viewing your website in. If you have an existing website, check the web analytics to see what devices are popular. Device popularity varies by location, so ensure you are using statistics that are relevant to you. Ensure you are including small screens, large screens, different browsers and different operating systems. Again, the Netflix blog discusses how they test for 1000 Android devices and is worth reading.

Conclusion

As a team, you need to follow the responsive design checklist and decide:

  • Whether responsive design, device specific sites or RESS is the right choice
  • If you are building a responsive design, which type of responsive design will you build?
  • Will you implement your responsive design using progressive enhancement or graceful degradation?

One you have decided, you need to make sure every person in your team sticks to these decisions, whether they work in design, user experience or technology.

If you do not, you will end up with a system that is poorly designed and contains messy, unmaintainable code. You will end up with some features that use graceful degradation and some that use progressive enhancement, and it will become extremely difficult for anyone to figure out what is going on. And you will end up with different types of responsive design, and an inconsistent user experience.

Let me know your thoughts on Responsive Design, and the Responsive Design Checklist below, especially if you can think of any other important considerations for building responsive designs.