Web Development Blog

Twitter

12 Jun, 2009

Making a website iPhone-friendly using CSS

Web Development » CSS, Design, Tutorials » Making a website iPhone-friendly using CSS

Unlike any other mobile web browsers, iPhone comes with Safari browser which makes it possible to view any website that works on Safari. However, the challenge is that the screen size of an iPhone is not as big as a traditional monitor and therefore, if you have got a website which has a width of say, 1000px, the website will appear really small and unreadable on an iPhone screen.

Screenshot of Web Development Blog on iPhone
Screenshot of Web Development Blog on iPhone

Here are the steps to make a website iPhone-friendly using just CSS.

1. Create a separate stylesheet for iPhone

Tips:
1. Hide unnecessary elements
On this blog, I set the following elements to display: none in CSS. Use display: none rather than visibility: hidden because visibility: hidden will also hide the content inside an element and not hide the element completely.
2. Use a fluid layout
Set the width of your main container (or any other containers) to 100% rather than a specific width in pixel.

For example:

body {
background-color: #fff;
}

.header, .footer {
width: 100%;
}

.sidebar {
display: none;
}
<link media="only screen and (max-device-width: 480px)" href="/iphone.css" type= "text/css" rel="stylesheet" />

The viewport of an iPhone is 320 pixels in portrait orientation and 480 pixels in landscape orientation.

2. Specify meta data for viewport

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />

Here, I am not specifying any width because I am using a fluid layout. Setting the user-scalable property to 0 (false) ensures that the user isn’t able to zoom in or out the website. Refer to Safari HTML Reference – Supported Meta Tags to see any other meta tags that you might want to use.

3. Create an icon

This is very much like a favicon that will be used when the user add your website to their home screen. Use the following code to specify a custom icon. The icon should be at least 57×57 pixel.

<link rel="apple-touch-icon" href="/iphone.png" />

apple-touch-icon
An example of apple-touch-icon for Facebook

apple-touch-icon
An example of apple-touch-icon for Web Development Blog

4. Putting it altogether

Add all of the above to the <head> section of your website.

<!-- Start iPhone -->
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<link rel="apple-touch-icon" href="/iphone.png" />
<link media="only screen and (max-device-width: 480px)" href="/iphone.css" type= "text/css" rel="stylesheet" />
<!-- End iPhone -->

For WordPress (template specific)

<!-- Start iPhone -->
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<link rel="apple-touch-icon" href="<?php echo bloginfo('template_url'); ?>/iphone.png" />
<link media="only screen and (max-device-width: 480px)" href="<?php echo bloginfo('template_url'); ?>/iphone.css" type= "text/css" rel="stylesheet" />
<!-- End iPhone -->

A few things to note

  • The overflow CSS property does not work very well on iPhone. The scrollbars aren’t displayed but you can use two fingers and scroll across the area.
  • This solution does not make the website light-weight because all elements on your website are still loaded. However, it does look neater and cleaner because many elements are hidden via CSS using display: none.
  • The ideal solution is to develop a special version of the website for iPhone using mobile detection script and essentially reduces the bandwidth required to load the website on mobile devices.
  • Have a look at a few websites that are optimisied for an iPhone for an inspiration. View this blog on an iPhone, check out iBloggr theme (WordPress iPhone Theme) or view demos of these mobile templates.

Recommended books

Interested in getting an iPhone friendly website for your company or organisation? Contact us at Anansi Web Development to find out how we may be able to help you.

Other similiar posts that you might be interested in:

14 Responses to "Making a website iPhone-friendly using CSS"

1 | Levon Gravett

June 21st, 2009 at 6:12 am

Avatar

Thank you for this really helped me a lot. I have one question tho as I am nee to mobi sites. How would I go about setting up the domain for the site I would like to have it as mobile.site.com how would I set this up so that the mobile device picks it up? Your help would be greatly appreciate. Many thanks. Levon

2 | eisabai

June 22nd, 2009 at 9:19 pm

Avatar

Hi Levon,
If you want to redirect your visitors to a different address/domain based on what browsers they are using, you can use this mobile user agent detection script: http://detectmobilebrowsers.mobi/

4 | Andy from Brand Aspect

September 18th, 2009 at 4:41 am

Avatar

This is a really useful post, but the key as always is planing your website. Hiding stuff may not be the best solution but it will be quicker. Its probably going to be easier to plan content structures for all media types from scratch. Well that rather than trying to create a stylesheet for an existing site on the basis that background image substitution would be one of the quicker ways to style using alternate stylesheets. Anyhow well done on the post mate.

5 | Optimising for iPhone Using CSS « Blog Relations

September 24th, 2009 at 8:33 pm

Avatar

[...] some simple optimisation of this site for iPhone using only CSS. I picked up some good tips here and [...]

6 | Optimizing the Web for the iPhone « Adventures in Internet Technology

November 6th, 2009 at 5:29 am

Avatar

[...] came across this fantastic resource. Finally, for information on CSS for the iPhone, I found this site. Possibly related posts: (automatically generated)No Title Categories: Uncategorized [...]

7 | iPhone Web App Resources | Ash White – MIST7500

November 6th, 2009 at 1:02 pm

Avatar

[...] Make a Website iPhone-friendly Using CSS [...]

8 | J

January 6th, 2010 at 3:15 am

Avatar

“Unlike any other mobile web browsers, iPhone comes with Safari browser which makes it possible to view any website that works on Safari.”

Ever heard of Opera and Opera Mobile? :)

9 | Star Config web design sydney

January 18th, 2010 at 5:51 pm

Avatar

thank you for explaning to us how to make it website i phone friendly using css, it is really great idea, i would like to try it

10 | Steve Rio

March 1st, 2010 at 1:16 pm

Avatar

Thanks! Awesome.

11 | Quick Tips For Creating a Mobile Optimized Site | Design Shack

March 24th, 2010 at 12:23 am

Avatar

[...] Making a website iPhone-friendly using CSS [...]

12 | WordPress iPhone App – a step by step user guide to using WordPress for iPhone - Web Development Blog

March 26th, 2010 at 12:15 pm

Avatar

[...] makes previewing and viewing post and pages on our blog a lot easier. We have written a tutorial on How to make a website iPhone-friendly using CSS. We also recommend you to read two great books on iPhone Web Development, Building iPhone Apps with [...]

13 | steve rhoades

August 26th, 2010 at 4:15 am

Avatar

Hoping someone can help.
Need to hire a web developer with some experience or interest in iphone app development
need php or javascript and css, html, jsp experience along with some experience in screen design.
professional experience preferred or a passionate hobbyist is a possibility.
good salary and employee benefits
contact: steve rhoades, 610-687-7742 or email me: steve@wrplacement.com
thanks

14 | Icechen1

August 26th, 2010 at 10:01 am

Avatar

WPtouch iPhone Theme is also a great way to make your Wordpress wite mobile-friendly by creating a theme for iPhone and iPod Touch, the mobile version of the site also works on Android. :)
.-= Icechen1´s last blog ..Google adds free phone calling in Gmail- Skype competitor =-.

Comment Form

ebook
Subscribe to our newsletter and receive FREE e-book "7 Days Exercise to Build More Traffic To Your Blog"
Your name:  
Your email:  

  • About
    The blog Web Development Blog is where I keep myself up to date with the latest technologies in the industry and share my ideas and thoug...
  • Adsense Tips and Tricks
    With personal and commercial blogs, community websites, and social pages becoming the hot topic of the Internet in the last few years, many...
  • Advertise With Us
    Web Development Blog is a blog about Web Development, Web Design, Web Applications, Web 2.0, AJAX, Search Engine Optimisation, Latest Techno...
  • Archive
    Grab yourself a cup of coffee or tea, sit back and browse through an archive of all the blog posts on Web Development Blog....
  • Choosing a Content Management System
    The most commonly asked question when it comes to Content Management System is whether to build or buy (pre-built). While there are many fa...
  • Coupons
    Use the following coupon codes, promos and discount codes to save money on web hosting, domain names, website templates, ebooks, software, p...
  • Customised WordPress Themes
    If you would like a customised WordPress theme for your blog or your website, read on: (or head to WordPress Themes page to get free WordPre...
  • Favourite Poems
    If by Rudyard Kipling If you can keep your head when all about you Are losing theirs and blaming it on you, If you can trust yourself w...
  • Favourites
    Books Web Development Books Magazines Glamour Reader's Digest Software Adobe Photoshop CS4 Trend Micro Antivirus + Antispyw...
  • How to Start a Blog?
    What's a blog? According to Wikipedia, a blog is a user-generated website where entries are made in journal style and displayed in a reve...
  • Introduction to JSP Standard Tag Library (JSTL Basics)
    Tag libraries to include in your .jsp page <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> &l...
  • Links
    Free Anonymous Proxy Increases your privacy and security on the Internet by using our free, fast and easy to use web proxy. data backu...
  • Making a Passive Income Online
    Passive income, in my opinion, means an income which does not require a lot of regular maintenance work or continuing effort. I have been t...
  • Online Distribution Channels
    One of the importances of any website or business is to bring your products or services to the right people and to reach the target audience...
  • Recent Projects
    Followings are some of the recent projects I have done in 2006 -- 2007. Check out my latest business venture Web design Sydney to get your...
  • Recommended Web Development Books
    Many developers often ask me what books I read and what books I recommend in regards to web development and web technologies such as AJAX, J...
  • Search
    Looking for something on Web Developement Blog? Use this search tool powered by Google Custom Search to find what you are looking for just ...
  • Seven Tips to Building an Online Presence for your Business
    1. Get a domain name for your business The first and foremost step in building an online presence is to secure a domain name for your busi...
  • Seven Tips to Increasing Your Website’s Traffic Using SEO
    SEO is the buzz word - many people have mentioned it and many have heard of it too, but very few people know how to implement it properly. ...
  • Subscribe
    Newsletter [newsletter] RSS 2.0 feeds Entries feed Comments feed Subscribe using your favourite web-based or desktop feed r...
  • Useful Linux Commands
    Find files older than 60 days find * -mtime +60 Delete files in backup folder which are older than 60 days rm -f `find /backup/ -mtime ...
  • Web Design Tips
    Nowadays, having a website for your business is like having a phone number. Almost every business has their own website, with their own doma...
  • Web Development Books
    Many developers often ask me what books I read and what books I recommend in regards to web development and web technologies such as AJAX, J...
  • Web Hosting Comparison Chart
    The following are some of the most popular web hosting providers. I have personally used the recommended ones. Hosting coupon codes will ...
  • Web Standards
    Web Standards is defined as a set of rules or specifications that should be followed when developing a website.  The main objectives o...
  • WordPress Themes
    All WordPress themes are designed and coded by esn studio, and licensed under GPL license. If you would like a customised WordPress theme fo...
  • Sam: Useful. I always forget the rel target one
  • Chronic Tinnitus: Hi, Thanks for taking the time to discuss a really confusing matter - I find Plesk so much more awkward than the cpanel that I'm used to. Thanks Chr
  • Serhiy: I personally liked the web hosting comparison chart. Especially the recommended *. I got Bluehost :) .-= Serhiy´s last blog ..

Interests

Web development, Web design, Open source technologies, Portal development, APIs, Web services, Social media applications, Search engine optimisation, Mobile application development, iPhone Apps, Web 2.0, Web 3.0, Latest Internet technologies

Misc.

  • bluehost Hosting $6.95/month
  • Joomla Templates