The future of Media Queries for email

Yesterday at the Litmus Email Design Conference in London, Mark Robbins raised an interesting point that in the very near future email will need to adapt not just to mobiles and tablets, but also to much larger devices such as televisions.

The W3C takes into account the fact that devices are still proliferating with its latest spec for Media Queries Level 4, some of which are being slowly implemented by WebKit, but which we can expect to come into effect in the near-ish future (it is still an Editor’s Draft).

There are a few potentially exciting new types of media queries that we will be able to use, such as:

orientation

‘Portrait’ is triggered when the height is greater than the width, and vice versa

aspect-ratio & device-aspect-ratio

color, color-index, monochrome

A series of queries that assess the color output of a device, the quality of that output or the depth of monoschrome output. Useful for targeting colour screens as opposed to e-ink, for example.

resolution

A more specific way to target resolutions than simply with pixel-density

pointer

Whether or not a device is a touch-screen or uses a mouse — could be useful for ensuring touch devices have buttons for links, whereas devices with a mouse can feature smaller text links (although there are some potential issues with this since some devices allow both a mouse to be connected and interaction via a touchscreen).

hover

Whether or not the device supports hover

And finally, my personal favourite: luminosity

The values are:

‘dim’

The device is used in a dim environment, where excessive contrast and brightness would be distracting or uncomfortable to the reader. For example: night time, or a dimly illuminated indoor environment.

‘normal’

The device is used in a environment with a level of luminosity in the ideal range for the screen, and which does not necessitate any particular adjustment.

‘washed’

The device is used in an exceptionally bright environment, causing the screen to be washed out and difficult to read. For example: bright daylight.

Since all media queries are dynamic this allows for styles that will adjust to the user’s environment.. a higher contrast for bright daylight with a more subdued, lower-contrast colour scheme for dim environments.

Support for any of these is basically non-existent at the moment, but it’s an exciting look into the future!

Media Queries in HTML Email: Cover all your bases

This post is pretty old and probably no longer relevant. I’m keeping it online for posterity but you no longer need to bother with the techniques listed here. I no longer use max-device-width or min-device-width at all in my media queries, relying solely on max-width and min-width.

Open Signal's visualisation of different device screen sizes — Android on the left, Apple on the right
Open Signal’s visualisation of different device sizes — Android on the left, Apple on the right

Update: Be sure to check the comments for further discussion where Lucas has suggested sticking with max-device-width alone, but pulling the media queries into the body of the email. This does also seem to fix the problem. Read the conversation for more.

These days it’s possible to hold a smartphone in your hand with a higher screen resolution than a computer. This can pose a small issue when using media queries since there are a few devices that can fit in your hand, but actually have way more pixels than your mobile design width.

What I’ve been using

In my experience up to now, it was best to use the following media query when coding HTML email, using 500px as an example*:

(I use screen instead of all to prevent any possible long-shot issues if an email is printed. It is potentially irrational.)

The reason to use max-device-width is because our old friend, Outlook.com on IE9, displays the mobile version of your email if you only use max-width (Such an amazing feature!).

*It’s a good idea to use max-width during development, so that you can easily resize your browser to preview the responsive behaviour.

Great. So what’s changed?

Well, now with all these new giant phones, they have a max-device-width of much larger — the HTC One, for example, has a physical screen resolution of 1920 x 1080. They ‘think’ their width is ~320px which means max-width would work, but we can’t because of the Outlook.com/IE9 bug mentioned above.

How to fix it? Easy! Just double up

The best way to fix this is to double up on your media query, and cover everything with a max-width of 550px, and a max-device-width of 550px.

I was concerned that Outlook.com/IE9 would still render the CSS contained in the media query because max-width is still there as an option, but it doesn’t. Thankfully, our problem is solved!

PS: This all originates from a bug I had with an HTC One displaying the desktop version of an email when using max-device-width. While plenty of smartphones have happily obeyed the max-device-width rule when they have physical pixel widths higher than their maximum display widths (the iPhone4+ displays at 320px wide when it actually has 640 physical pixels across), for some reason I haven’t seen this problem until testing with HD devices. Pixel density and media queries makes me go a bit woolly between the ears at times, so my assumption is that the HTC One ignored max-device-width because it has 1080 pixels to play with, but I could be wrong. If you know more, please jump in the comments!