Web Developers Are Fucking Hypocrites
This post, and the related CSS code to target the iPhone 4’s browser, came through my Twitter stream multiple times today.
I think the things Apple are doing, and the advances they are making in the mobile phone and hand-held Internet device markets are amazing. I think it’s great that consumers (with the help of device makers) are redefining where, when, and especially how they interact with devices and data. I think the iPhone is cool. [I don't own one (I do have an iPod touch for testing), but that new display is incredibly tempting...]
So here we have this awesome new device which allows us to access all the same information we previously only could from a desktop (or laptop) computer. Apple even went out of their way to reinvent the way we interact with and browse that information so that we could have "the full Internet experience," and not some scaled-down mobile version.
See where I'm going with this?
It seems to me that we have so called 'standardistas' promoting information on how to design for a specific device, when the last — what has it been now? — 10 years have been all about getting away from browser sniffing, and moving toward adaptable, degradable design. In enough time, there won't be a 'mobile web,' it will just be the standard 'desktop web' that we're used to, and "these websites over here that only work on the iPhone." Thankfully, I'm not the only one, nor anywhere near the first person to realize this.
But a funny thing happened. Web developers started making versions of their Web sites optimized for the iPhone. Some had these versions available shortly after the iPhone launched. But since then many of the major sites like Google, Yahoo, FaceBook, Amazon, and so on, recognize when they are being browsed on an iPhone and will display an iPhone-specific view instead of the one you see on your Mac or PC.
So Apple gave us the real Web, but the Web site developers took it away.
The iPhone has become an obsession. If we don’t pay attention, we’ll have a mobile web that only works on the iPhone. And then we’ll have the real mobile web that wasn’t made by us and doesn’t give a shit about web standards and best practices.
[ ... ]
We’re doing exactly the same as ten years ago. We now say “iPhone” instead of “IE6,” but otherwise nothing’s changed.
What’s the solution?
First you have to identify whether or not you have a problem. If you're designing for a specific audience, namely iPhone 4 users only, then there is no problem. At the moment, though, that’s a pretty small target audience. Additionally, if you're only using this media query to "clean up" the appearance of your site when viewed on the iPhone 4, it’s probably safe to bet that you're doing things the 'right' way.
Why use this specific targeting at all, especially when there are much better alternatives? Another trend which has resurfaced recently is being called Responsive Design. It’s sort of a rethinking of the elastic and liquid layouts of a few years back.
Using the very same idea, CSS media queries can be used to target all devices of certain display capabilities, for example display width and or height, not just the fact that their "device pixel ratio" (whatever the hell that actually means) is a certain value.
These media queries, although commonly in use for serving styles to iPhone, also work for any other browser which will recognize them. Consider this a way of 'future-proofing' your website. If I come along one day with a device that has a screen size similar, if not the same, as the iPhone, your website will already be appropriately styled for my browsing experience, no modification necessary.
Consider the following:
@media screen and (max-device-width: 480px) { /* iPhone 2/3 */ }
@media screen and (max-device-width: 960px) { /* iPhone 4 */ }
@media screen and (max-device-width: 1280px) { /* etcetera… */ }
Media queries can be a very powerful tool, and certainly don't stop at the functionality shown above. By changing max-device-width to device-width further style customization is possible:
@media screen and (max-width: 320px) {
/* iPhone 2/3 portrait AND ANY DEVICE WITH SIMILAR DISPLAY SPECS */
}
@media screen and (max-width: 960px) {
/* iPhone 4 landscape AND ANY OTHER DEVICES WITH MATCHING SPECS */
}
@media screen and (max-width: 768px) and (orientation: portrait) {
/* iPad portrait, etcetera… */
}
These media queries show some specific, powerful examples of targeting specific devices in specific modes, and can certainly be used for providing that functionality (if that’s your end-goal), but the point is that they shouldn't. They are powerful enough to give the designer the ability to build a site’s HTML once and style it endless ways provided some simple conditions of the device on which it is being viewed — not just the iPhone.
Go forth, and design wisely.