Responsive Design – Harnessing The Power of Media Queries

Webmaster Level: Intermediate / Advanced

We love data, and spend a lot of time monitoring the analytics on our websites. Any web developer doing the same will have noticed the increase in traffic from mobile devices of late. Over the past year we’ve seen many key sites garner a significant percentage of pageviews from smartphones and tablets. These represent large numbers of visitors, with sophisticated browsers which support the latest HTML, CSS, and JavaScript, but which also have limited screen space with widths as narrow as 320 pixels.

Our commitment to accessibility means we strive to provide a good browsing experience for all our users. We faced a stark choice between creating mobile specific websites, or adapting existing sites and new launches to render well on both desktop and mobile. Creating two sites would allow us to better target specific hardware, but maintaining a single shared site preserves a canonical URL, avoiding any complicated redirects, and simplifies the sharing of web addresses. With a mind towards maintainability we leant towards using the same pages for both, and started thinking about how we could fulfill the following guidelines:

  1. Our pages should render legibly at any screen resolution
  2. We mark up one set of content, making it viewable on any device
  3. We should never show a horizontal scrollbar, whatever the window size

responsive_chromeStacked content, tweaked navigation and rescaled images – Chromebooks

Implementation

As a starting point, simple, semantic markup gives us pages which are more flexible and easier to reflow if the layout needs to be changed. By ensuring the stylesheet enables a liquid layout, we’re already on the road to mobile-friendliness. Instead of specifying width for container elements, we started using max-width instead. In place of height we used min-height, so larger fonts or multi-line text don’t break the container’s boundaries. To prevent fixed width images “propping open” liquid columns, we apply the following CSS rule:

img {
max-width: 100%;
}

Liquid layout is a good start, but can lack a certain finesse. Thankfully media queries are now well-supported in modern browsers including IE9+ and most mobile devices. These can make the difference between a site that degrades well on a mobile browser, vs. one that is enhanced to take advantage of the streamlined UI. But first we have to take into account how smartphones represent themselves to web servers.

Viewports

When is a pixel not a pixel? When it’s on a smartphone. By default, smartphone browsers pretend to be high-resolution desktop browsers, and lay out a page as if you were viewing it on a desktop monitor. This is why you get a tiny-text “overview mode” that’s impossible to read before zooming in. The default viewport width for the default Android browser is 800px, and 980px for iOS, regardless of the number of actual physical pixels on the screen.

In order to trigger the browser to render your page at a more readable scale, you need to use the viewport meta element:

a name=”viewport” content=”width=device-width, initial-scale=1″>

Mobile screen resolutions vary widely, but most modern smartphone browsers currently report a standard device-width in the region of 320px. If your mobile device actually has a width of 640 physical pixels, then a 320px wide image would be sized to the full width of the screen, using double the number of pixels in the process. This is also the reason why text looks so much crisper on the small screen – double the pixel density as compared to a standard desktop monitor.

The useful thing about setting the width to device-width in the viewport meta tag is that it updates when the user changes the orientation of their smartphone or tablet. Combining this with media queries allows you to tweak the layout as the user rotates their device:

@media screen and (min-width:480px) and (max-width:800px) {
/* Target landscape smartphones, portrait tablets, narrow desktops

*/
}

@media screen and (max-width:479px) {
/* Target portrait smartphones */
}

In reality you may find you need to use different breakpoints depending on how your site flows and looks on various devices. You can also use the orientation media query to target specific orientations without referencing pixel dimensions, where supported.

@media all and (orientation: landscape) {
/* Target device in landscape mode */
}

@media all and (orientation: portrait) {
/* Target device in portrait mode */
}

Stacked content, smaller images – Cultural Institute

A media queries example

We recently re-launched the About Google page. Apart from setting up a liquid layout, we added a few media queries to provide an improved experience on smaller screens, like those on a tablet or smartphone.

Instead of targeting specific device resolutions we went with a relatively broad set of breakpoints. For a screen resolution wider than 1024 pixels, we render the page as it was originally designed, according to our 12-column grid. Between 801px and 1024px, you get to see a slightly squished version thanks to the liquid layout.

Only if the screen resolution drops to 800 pixels will content that’s not considered core content be sent to the bottom of the page:

@media screen and (max-width: 800px) {
/* specific CSS */
}

With a final media query we enter smartphone territory:

@media screen and (max-width: 479px) {
/* specific CSS */
}

At this point, we’re not loading the large image anymore and we stack the content blocks. We also added additional whitespace between the content items so they are more easily identified as different sections.

With these simple measures we made sure the site is usable on a wide range of devices.

responsive_aboutStacked content and the removal of large image – About Google

Conclusion

It’s worth bearing in mind that there’s no simple solution to making sites accessible on mobile devices and narrow viewports. Liquid layouts are a great starting point, but some design compromises may need to be made. Media queries are a useful way of adding polish for many devices, but remember that 25% of visits are made from those desktop browsers that do not currently support the technique and there are some performance implications. And if you have a fancy widget on your site, it might work beautifully with a mouse, but not so great on a touch device where fine control is more difficult.

The key is to test early and test often. Any time spent surfing your own sites with a smartphone or tablet will prove invaluable. When you can’t test on real devices, use the Android SDK or iOS Simulator. Ask friends and colleagues to view your sites on their devices, and watch how they interact too.

Mobile browsers are a great source of new traffic, and learning how best to support them is an exciting new area of professional development.

Some more examples of responsive design at Google:

Written by Rupert Breheny, Edward Jung, & Matt Zürrer, Google Webmaster Team

Website:
Build My Site

Deke’s Techniques #2: Branding Type On a Texture

Deke’s Techniques — Branding type on a texture. This week’s technique features lynda.com’s author Deke McClelland, showing you how to virtually brand your chosen type into any surface imaginable in Photoshop. The specific background (leather, cowhide, parchment, corrugated paper) doesn’t matter. The key to this technique is turning your background (or your hand, as it were) into a displacement map, then applying some Burn tool action and a little Bevel and Emboss. Watch more at: Deke’s Techniques

See Related Free Resources:

Website:
Build My Site

Five Common SEO Mistakes (and six good ideas!)

Webmaster Level: Beginner to Intermediate

To help you avoid common mistakes webmasters face with regard to search engine optimization (SEO), I filmed a video outlining five common mistakes I’ve noticed in the SEO industry. Almost four years ago, we also gathered information from all of you (our readers) about your SEO recommendations and updated our related Help Center article given your feedback. Much of the same advice from 2008 still holds true today — here’s to more years ahead building a great site!

If you’re short on time, here’s the gist:

Avoid these common mistakes

1. Having no value proposition: Try not to assume that a site should rank #1 without knowing why it’s helpful to searchers (and better than the competition) :)

2. Segmented approach: Be wary of setting SEO-related goals without making sure they’re aligned with your company’s overall objectives and the goals of other departments. For example, in tandem with your work optimizing product pages (and the full user experience once they come to your site), also contribute your expertise to your Marketing team’s upcoming campaign. So if Marketing is launching new videos or a more interactive site, be sure that searchers can find their content, too.

3. Time-consuming workarounds: Avoid implementing a hack rather than researching new features or best practices that could simplify development (e.g., changing the timestamp on an updated URL so it’s crawled more quickly instead of easily submitting the URL through Fetch as Googlebot).

4. Caught in SEO trends: Consider spending less time obsessing about the latest “trick” to boost your rankings and instead focus on the fundamental tasks/efforts that will bring lasting visitors.

5. Slow iteration: Aim to be agile rather than promote an environment where the infrastructure and/or processes make improving your site, or even testing possible improvements, difficult.

Six fundamental SEO tips

1. Do something cool: Make sure your site stands out from the competition — in a good way!

2. Include relevant words in your copy: Try to put yourself in the shoes of searchers. What would they query to find you? Your name/business name, location, products, etc., are important. It’s also helpful to use the same terms in your site that your users might type (e.g., you might be a trained “flower designer” but most searchers might type [florist]), and to answer the questions they might have (e.g., store hours, product specs, reviews). It helps to know your customers.

3. Be smart about your tags and site architecture: Create unique title tags and meta descriptions; include Rich Snippets markup from schema.org where appropriate. Have intuitive navigation and good internal links.

4. Sign up for email forwarding in Webmaster Tools: Help us communicate with you, especially when we notice something awry with your site.

5. Attract buzz: Natural links, +1s, likes, follows… In every business there’s something compelling, interesting, entertaining, or surprising that you can offer or share with your users. Provide a helpful service, tell fun stories, paint a vivid picture and users will share and reshare your content.

6. Stay fresh and relevant: Keep content up-to-date and consider options such as building a social media presence (if that’s where a potential audience exists) or creating an ideal mobile experience if your users are often on-the-go.

Good luck to everyone!

Written by Maile Ohye, Developer Programs Tech Lead

See Other Related Free Resources:

Website:
Build My Site

Infographics: Drawing Relationships Between Characters

Watch more at: Infographics: Visualizing Relationships

This Infographics tutorial titled “Drawing relationships for your characters” is from chapter one of the Infographics: Visualizing Relationships course presented by lynda.com author Shane Snow. This specific tutorial describes how to visualize relationships between different characters within a circular infographic. The complete Infographics: Visualizing Relationships course has a total duration of 50 minutes and 42 seconds and describes how to build multi-relationship radial diagrams, create legends, and illustrate connections between relationships.


Infographics: Visualizing Relationships table of contents:



Introduction
1. Creating a Multi-Relationship Circle Visualization
2. Adding the Finishing Touches
Conclusion

See Related Resources From lynda.com:

Website:
Build My Site

The Google Maps API and Chrome DevTools

Learn how the Chrome Developer Tools can make development with the Maps API faster and easier. If you’d like to know more, see the links below.

Chrome DevTools documentation:
http://goo.gl/UCVxD

For more DevTools screencasts than you can handle:
http://www.html5rocks.com/en/slides#devtools

From the jQuery Docs:
“jQuery() — which can also be written as $() — searches through the DOM for any matching elements and *creates a new jQuery object that references these elements*.”
http://api.jquery.com/jQuery/#jQuery1

See Related Free Resources:

Website:
Build My Site

How to Create a Facebook Like Box

This Social Media Marketing tutorial shows how to create a Facebook Like Box for your web site or blog. Watch more at: Social Media Marketing with Facebook and Twitter

This specific tutorial is just a single movie from chapter five of the Social Media Marketing with Facebook and Twitter course presented by lynda.com author Anne-Marie Concepción. The complete Social Media Marketing with Facebook and Twitter course has a total duration of 5 hours and 31 minutes, and shows dozens of ways to promote a company’s brand, increase sales, engage customers, and drive site traffic using Facebook and Twitter.

Social Media Marketing with Facebook and Twitter table of contents:

Introduction
1. The Big Picture
2. Twitter Basics
3. Facebook Overview
4. Tweeting for Business
5. Facebook Pages for Business
6. Extending Social Media Marketing
7. Conclusion

See Related Free Resources:

Website:
Build My Site

Eye Tracking Study Comparing Mobile and Desktop

In this study we show a series of visually striking eye tracking hotspot-maps to highlight the differences between where people look on a desktop and mobile screen. We think this research will be of interest to anyone working on mobile strategy. Whether you’re looking to design a mobile site, or already have one and are considering mobile advertising.

Eye tracking demonstrates:

  • The traditional above and below the fold does not exist on a mobile website; the screen is scrolled and checked carefully.
  • Mobile advertising is an effective way of capturing people‘s attention and are similar in effectiveness to desktop adverts.
  • Although people view mobile websites for less time than when using a desktop, their attention is more focused.

See Related Free Resources:

Website:
Build My Site

How to Control Adaptable Tablet Layouts

This tutorial describes how to create an adaptable user-interface that improves tablet and mobile user-experience, and helps performance.

This specific tutorial is just a single movie from chapter one of the Flex 4.6 and AIR 3.0 Mobile Apps New Features course presented by lynda.com author James Talbot. The complete Flex and AIR course has a total duration of 1 hour and 50 minutes and describes how to build components for mobile user-interfaces and how to enable applications to use parts of the host operating systems that were previously unavailable.

Watch more of this course on lynda.com:
Flex 4.6 and AIR 3.0 New Features for Mobile Apps

Flex 4.6 and AIR 3.0 Mobile Apps New Features table of contents:

Introduction
1. Building Tablet Applications
2. Building Flex Applications that Integrate with Native Applications
3. Testing and Debugging Flex Mobile Applications
Conclusion

See Related Free Resources:

Website:
Build My Site

WordPress 3.4 “Green”

WordPress 3.4 is here and out the door. We’ve dubbed this release “Green” in honor of guitarist Grant Green whose soulful simplicity has kept many of us company during this release.

This release includes significant improvements to theme customization, custom headers, Twitter embeds, and image captions — here’s a short clip with the highlights:

For Users

The biggest change in 3.4 is the theme customizer which allows you to play around with various looks and settings for your current theme or one you’re thinking about switching to without publishing those changes to the whole world. For themes that support it, you can change colors, backgrounds, and of course custom image headers. We have more planned for the customizer down the road.

Throughout the rest of the admin you’ll notice tweaks to make your everyday life easier. For example, if you have lots of themes we’ve made it quicker to browse them all at once without paging. We’ve made it possible to use images from your media library to populate custom headers, and for you to choose the height and width of your header images.

We’ve expanded our embed support to include tweets: just put a Twitter permalink on its own line in the post editor and we’ll turn it into a beautiful embedded Tweet. And finally, image captions have been improved to allow HTML, like links, in them.

For Developers

There are hundreds of under-the-hood improvements in this release, notably in the XML-RPC, themes, and custom header APIs, and significant performance improvements in WP_Query and the translation system. The Codex has a pretty good summary of the developer features, and you can always dive into Trac directly.

We’ve also put together a busy developer’s field guide to the new APIs in 3.4.

See related resources for WordPress:

Website:
Build My Site