An Introduction To Object Oriented CSS (OOCSS)

e-Commerce, Online marketing & SEO, Print Design, Web Design

An Introduction To Object Oriented CSS (OOCSS)

3 Comments 30 January 2012

Have you ever heard the phrase “Content is King”? Being a Web developer, and therefore having a job that’s often linked to content creation, it’s likely you have. It’s a fairly overused but true statement about what draws visitors to a site.

From a Web developer’s perspective, however, some may argue that speed is king. More and more, I’m starting to favour that stance. In recent years many experienced front-end engineers have offered their suggestions on how we can improve the user experience by means of some performance best practices.

Unfortunately, CSS seems to get somewhat overlooked in this area while many developers (for good reason) focus largely on JavaScript performance and other areas.

In this post, I’ll deal with this often overlooked area by introducing you to the concept of object oriented CSS and how it can help improve both the performance and maintainability of your Web pages.

[Editor's note: A must-have for professional Web designers and developers: The Printed Smashing Books Bundle is full of practical insight for your daily work. Get the bundle right away!]

The Principles Of OOCSS

As with any object-based coding method, the purpose of OOCSS is to encourage code reuse and, ultimately, faster and more efficient stylesheets that are easier to add to and maintain.

OOCSS

As described on the OOCSS GitHub repo’s Wiki page, OOCSS is based on two main principles.

Separation of Structure From Skin

Almost every element on a styled Web page has different visual features (i.e. “skins”) that are repeated in different contexts. Think of a website’s branding — the colors, subtle uses of gradients, or visible borders. On the other hand, other generally invisible features (i.e. “structure”) are likewise repeated.

When these different features are abstracted into class-based modules, they become reusable and can be applied to any element and have the same basic result. Let’s compare some before and after code so you can see what I’m talking about.

Before applying OOCSS principles, you might have CSS that looks like this:

#button {
	width: 200px;
	height: 50px;
	padding: 10px;
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}

#box {
	width: 400px;
	overflow: hidden;
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}

#widget {
	width: 500px;
	min-height: 200px;
	overflow: auto;
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}

The three elements above have styles that are unique to each, and they’re applied with the non-reusable ID selector to define the styles. But they also have a number of styles in common. The common styles might exist for branding purposes or consistency of design.

With a little bit of planning and forethought, we can abstract the common styles so the CSS would end up instead like this:

.button {
	width: 200px;
	height: 50px;
}

.box {
	width: 400px;
	overflow: hidden;
}

.widget {
	width: 500px;
	min-height: 200px;
	overflow: auto;
}

.skin {
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}

Now all the elements are using classes, the common styles are combined into a reusable “skin” and nothing is unnecessarily repeated. We just need to apply the “skin” class to all the elements and the result will be the same as what the first example would produce, except with less code and a possiblity for further reuse.

Separation of Containers and Content

The second principle described on the OOCSS GitHub wiki page is the separation of containers from their content. To illustrate why this is important, take the following CSS:

#sidebar h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: .8em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 3px 3px 6px;
}

These styles will apply to any third-level headings that are children of the #sidebar element. But what if we want to apply the exact same styles to third-level headings that appear in the footer, with the exception of a different font size and a modified text shadow?

Then we would need to do something like this:

#sidebar h3, #footer h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 2em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 3px 3px 6px;
}

#footer h3 {
	font-size: 1.5em;
	text-shadow: rgba(0, 0, 0, .3) 2px 2px 4px;
}

Or we might end up with something worse:

#sidebar h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 2em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 3px 3px 6px;
}

/* other styles here.... */

#footer h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 1.5em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 2px 2px 4px;
}

Now we’re unnecessarily duplicating styles, and might not realize it (or simply don’t care). With OOCSS, we’re encouraged to give more forethought to what is common among different elements, then separate those common features into modules, or objects, that can be reused anywhere.

The styles that are declared using the descendant selector in those above examples are not reusable, because they are dependent on a particular container (in this case either the sidebar or the footer).

When we use OOCSS’s class-based module building, we ensure that our styles are not dependent on any containing element. This means they can then be reused anywhere in the document, regardless of structural context.

A Real-World Example

To further illustrate how OOCSS can be used, I’ll use something similar to what I did on my site’s recent redesign. After coding the inner header element on my site, I realized that the basic structural styles for the inside of the header could be reused on other elements on the page.

So here’s something along the lines of what I had when I started styling my header:

.header-inside {
	width: 980px;
	height: 260px;
	padding: 20px;
	margin: 0 auto;
	position: relative;
	overflow: hidden;
}

A few of the styles listed here are unique to the .header-inside element. But the rest can form a module that I can reuse. So I can abstract the structural styles into their own reusable class. Here’s the result:

.globalwidth {
	width: 980px;
	margin: 0 auto;
	position: relative;
	padding-left: 20px;
	padding-right: 20px;
	overflow: hidden;
}

.header-inside {
	padding-top: 20px;
	padding-bottom: 20px;
	height: 260px;
}

The styles belonging to the .globalwidth class cover the following:

  • A fixed width
  • Centering using margin: auto
  • Relative positioning to create a positioning context for child elements
  • Left and right padding of 20px
  • Overflow set to “hidden” for clearfixing

Now we’re free to use these styles on any elements that require these same characteristics by simply adding that class to the desired element — without writing a single extra line of CSS.

For my site, I reused these structural styles on the primary content element and the inner footer element. Depending on the design, these styles could also apply to a horizontal navigation element that might appear between the header and the content, or any other element that has a fixed-width and needs to be centered on the page.

After adding the “globalwidth” styles to these elements, the markup would look something like this:

<header>
	<div>
	</div>
</header>

<div>
</div>

<footer>
	<div>
	</div>
</footer>

Some may feel that this type of styles abstraction clutters the HTML and goes against the principle of separating markup from presentation.

But putting aside any debates about how this might affect the markup, no one can question that this abstraction has now made it easier to track down and modify the common styles that are used to structure these three elements.

The Media Object

One of the pioneers of the OOCSS movement is Nicole Sullivan. She’s created a reusable module called the media object which, as she explains, can save hundreds of lines of code.

OOCSS

The media object is a great example of the power of OOCSS because it can contain a media element of any size with content to its right. Although many of the styles that apply to the content inside of it — and even the size of the media element itself — could change, the media object itself has common base styles that help avoid needless repetition.

The Benefits Of OOCSS

I’ve already alluded to some of the benefits of OOCSS. Here I’ll expand on these.

Faster Websites

The performance benefits of OOCSS should be fairly clear. If you have fewer styles that are repeated in your CSS, then this will lead to smaller file sizes and thus faster downloading of those resources.

It’s true that markup will be more cluttered and thus create larger HTML files. But in many cases the amount of loss in markup performance will be greatly surpassed by the amount of gain in stylesheet performance.

Another concept to keep in mind is something that the OOCSS wiki refers to as performance freebies. This refers to the fact that every time you reuse something in your CSS, you’re essentially creating new styled elements with zero lines of CSS code. For large, high-traffic projects, these “freebies” could be a crucial performance gain.

Maintainable Stylesheets

With OOCSS, instead of a constantly growing stylesheet full of specificity wars, you’ll have an easy to maintain set of modules where the natural cascade plays an important role.

When making additions to an existing site, you won’t be adding new styles to the bottom of your stylesheet without regard for what came before. Instead you’ll be reusing existing styles and extending your styles based on existing rule sets.

With this type of forethought, it’s possible to create entire pages while coding very little CSS. Any existing CSS modules can serve as a basis for all new pages, and any new CSS will be minimal. In some cases you might even be able to create a new fully-styled page without coding a single line of CSS.

These maintainability benefits also extend to the robustness of your stylesheets. Because the styles are modular, pages built on OOCSS will be less likely to break when a new developer starts to use the stylesheet.

Points Worth Noting

OOCSS has created a great deal of discussion in the community, raising some controversies. Here I’ll try to dispel a couple of common misconceptions.

You Can Still Use IDs

If you decide to work exclusively in an OOCSS manner, then your styles will be based largely on CSS classes, and you won’t be styling elements using the ID selector.

Because of this, many have falsely claimed that OOCSS encourages dropping the use of IDs completely. But this is not true.

The rule to avoid IDs is, more specifically, don’t use IDs in selectors. So it’s perfectly acceptable to use OOCSS principles (and thus avoid styling using the ID selector) while using IDs in your HTML for JavaScript hooks and fragment identifiers.

Of course, you may have a situation where you already have an ID applied to an element that you know is unique to the page. So, you can save a few bytes by avoiding adding a class to that element and instead style it using an ID selector. But even in this instance, it’s much safer to rely on a class to ensure you don’t run into specificity problems in the future.

Dealing With Smaller Projects

For smaller sites and apps, you could certainly make the case that OOCSS would be overkill. So don’t take this article as an advocacy for OOCSS in all circumstances — it will vary depending on the project.

Nonetheless, I think it’s a good idea, at the very least, to start thinking in terms of OOCSS in all your projects. Once you get the hang of it, I’m sure you’ll find it much easier to get it working on bigger projects where the benefits would be more noticeable and relevant.

Some Guidelines For Implementation

Getting started working with OOCSS could take time. I’m still working on it, so I don’t claim to have all the answers and experience in this area.

But here are some things you might want to start doing to help you get into an OOCSS mode of thinking:

  • Avoid the descendent selector (i.e. don’t use .sidebar h3)
  • Avoid IDs as styling hooks
  • Avoid attaching classes to elements in your stylesheet (i.e. don’t do div.header or h1.title)
  • Except in some rare cases, avoid using !important
  • Use CSS Lint to check your CSS (and know that it has options and method to its madness)
  • Use CSS grids

There will obviously be times when some of these rules will be broken, but overall, these are good habits to develop and will lead to stylesheets that are smaller and easier to maintain.

Running an effective Email marketing campaign

Online marketing & SEO, Web Design

Running an effective Email marketing campaign

1 Comment 30 January 2012

You check your e-mail in the morning before commencing work.

How many of these are unsolicited mails? How much of it is spam?

How many mails do you actually bother to open and read, let alone act on it?

Chances are a good 75% of your mails are unsolicited/spam, resulting in them ending up in the recycle bin, unread.

Email marketing is one of the cost effective and time saving methods to market your products and services. These pointers will help you target your audience correctly as well as get a bang for your buck.

  1. Give the option for your consumers to subscribe to marketing emails on your website. Do not forget to mention that their contact details would not be shared with anyone.
  2. You should also use a transparent email ID when sending out emails. Rather than using admin@yourcompany.com, you can use nameofproduct@yourcompany.com.
  3. The Subject Line will have to include text that will grab the attention of your customers, like special discounts or newest products. It’s best to refrain from using abbreviations, slang and hyperbole.
  4. Images should be used moderately to ensure that the content is captivating but should not include high resolution images, which would take a long time to download.
  5. Your marketing email should prompt the user to act. i.e. reply to the email, visit your website etc.
  6. Personalise the email by including the customer’s name and ending the mail with a signature
  7. Include all your contact details
  8. Include a note requesting the client to add you to their contact list
  9. Do not include attachments as most of the time your email would not have the expected open rate due to fear of malicious attacks
  10. Include an option to unsubscribe as well so that the user is aware that you are not imposing upon his/ her privacy and that he/she can opt out anytime

When you outsource your e-mail marketing campaign to a professional online marketing agency, you can rest assured that all these aspects will be handled and you will get the best possible response rate from your target audience.

70% support social network blackout during future riots

Online marketing & SEO

70% support social network blackout during future riots

No Comments 30 January 2012

A poll of 973 adults, carried out by online security firm, Unisys has concluded that 70% supported pulling the plug of Twitter, Facebook and BlackBerry Messenger (BBM), while only about 27% disagreed during times of riots and uncertainty.

This majority also agree that the Government should have access to data on social network users to prevent the occurrences of coordinated crime. It must be noted however that it was mostly the over-65s who opted for action against social media whilst the heaviest users, 18 to 24-year-olds were generally against it.

The fact that a majority support pulling the plug on Social Media during times of crises as there is evidence that most people were using Social Media to ensure that their friends and peers were safe and also to keep track of what was going on during the unrest. It is also evident from the speed at which Police were able to pinpoint riot locations based on Social Media and minimise damages.

Online marketing & SEO

SEO translating into ROI for business websites

3 Comments 30 January 2012

Search Engine Optimisation (SEO) is a phrase that has been gaining popularity as of late. We all know what it is all about – optimising a website to ensure high rankings on search engine results. This paves way for increased exposure in the overtly cluttered internet platform. Increased exposure translates into increased bottom-line via higher conversion rates (number of visitors to site vs. number of visitors who sign up for a service/newsletter or download a file). Although many doubt the actual capabilities of SEO, saying that they are simply black hat techniques used to increase rankings, which search engines will identify and take corrective action, resulting in the website being blacklisted.

However, SEO, when done right, can be a business’s best friend. Why? Return on Investment (ROI). Let’s get into more detail.

At present the ROI on ethical SEO from an online marketing agency is 1:15, i.e. every dollar invested by the organisation gives a return of $15 (on average). Also, unlike traditional marketing initiatives, SEO, along with other online marketing activities such as e-mail, social media, paid search/PPC, allows one to measure results. This too is a boon to professional number crunchers as they are able to measure ROI. Current surveys show that an overwhelming number of successful companies are spending time and money on social media, which is a component of SEO. Staggering 78% of Inc.500 companies use Facebook and 73% use Twitter. Companies need to regularly monitor their ROI from SEO and identify the low ROI projects and do away with them whilst focusing on high ROI projects.

A simple question to ask yourself to evaluate the success of your online marketing campaign – “Is the online marketing translating into online sales or sales leads?”

This question will form the cornerstone of all your online marketing activities, from basic e-mail campaigns to complex SEO strategies.

From Monitor To Mobile: Optimizing Email Newsletters With CSS

Online marketing & SEO

From Monitor To Mobile: Optimizing Email Newsletters With CSS

No Comments 30 January 2012

HTML email has a reputation for being a particularly tough design medium. So tough, in fact, that many designers regard coding and testing even the simplest email design to be almost as bad as fixing display quirks in Internet Explorer 6, and only slightly better than a tooth extraction. So, it’s with much courage that I tell you today about using CSS in email newsletters: what works, where it’s going and what you should do next.

After reading this article, you will hopefully come away with a few ideas on how to start coding email designs with improved readability and usability when viewed in Web, mobile and email desktop clients alike. Also included are a variety of resources to get you on the right path with using CSS in email.

Then again, the shaky state of email standards today may convince you that plain-text email is the way to go. The choice is yours.

[Editor's note: Have you already got your copy of our Printed Smashing Book #2? The book covers best practices and techniques for professional Web designers and developers.]

CSS In HTML Email: The Good, The Bad And The Mobile-Ready

If you’re about to embark on your first HTML email coding job, then you probably come from a Web background and are keen to flex a little CSS3 muscle, get a little JavaScript action happening, drop those shadows…

Not so fast. As any old hat to the email game can tell you, what works on the Web and what works in email are about as far apart as Sydney and Stockholm. For the most part, this is because pretty much every email client has its own way of doing things; while there are perhaps half a dozen browsers to test against when coding a Web page, there are literally dozens of email clients, many of which feature radically different CSS implementations.

But before you give up hope, here’s some advice to get you through the night:

  • A lot of CSS properties (such as font, color and border) work fine across many of the most popular email clients. Once you know which ones they are, you can tailor your designs accordingly.
  • When a CSS property doesn’t work so well, there are often workarounds (such as using cellpadding in tables instead of padding).
  • When workarounds don’t exist, focus on graceful degradation.
  • Your design will never look exactly the same across all email clients, no matter how you use CSS. Once you (and your clients) make peace with this, I guarantee you will sleep better at night.
  • Keep it simple. The less complicated your design and layout, the less likely something will go wrong. Favor table layouts over divs, and make sure your message is readable (which means text, not images).

At this point, you may be saying to yourself, “Well, this all just sounds too hard.” So, perhaps I should remind you how beautiful an HTML email can look, with just a sprinkling of CSS:

ABC Widgets Newsletter

For a more realistic view of what this design will look like in the inbox, here’s the same email in Gmail and Outlook 2007. Both are notoriously tricky email clients to work with:

Gmail

Outlook 2007

See? Ain’t so bad after all. But what’s more exciting is how you can use CSS to adapt an HTML email for optimal display on mobile devices. Here’s the same newsletter as viewed on the iPhone:

Newsletter on the iPhone with mobile CSSImages with mobile CSS

For comparison, let’s look at the same email newsletter without mobile-specific CSS:

Newsletter without mobile cssImages without mobile CSS

The change might seem subtle, but applying a mobile-specific style sheet has improved the readability of the email considerably. It has also allowed us to remove a lot of visual clutter (like the “Widget August 2011 Newsletter” text) that would have taken up valuable real estate on a small screen.

So, we’ve gone from an email layout that requires a lot of pinching and zooming, to one that can be easily read with a linear scrolling motion, using CSS alone. We’ll look at how you can apply similar improvements to your email campaigns in a moment. But first, let’s start with some of the fundamentals of using CSS in your HTML email designs.

The State Of CSS Support In Email Today

When I mentioned that a lot of CSS properties out there work fine in many email clients, I wasn’t trying to be vague. Thankfully, the research into what works and what doesn’t has already been done. You need only skim this guide to CSS support in email clients to see what properties are within and off limits. Or just know that most of your CSS rendering troubles will come from Outlook 2010, Lotus Notes and Gmail, due to their refusal to do anything useful with CSS style sheets.

These issues are nothing new. Indeed, the battle for market share between email clients that play nice with CSS versus those that don’t has been pitched for years now. But progress is being made. Looking at the data from over 3 billion emails sent, we found that mobile email clients have gained ground dramatically with the growth of mobile professionals. In fact, one in five emails are now opened on a mobile device. Here is how desktop, Web and mobile email clients have fared comparatively over the last two years:

Email Client Trends, June 2011
Desktop, Web and mobile email client market share, 2009 to 2011.

Mobile’s ascent is great news for email designers everywhere for one reason: roughly 75% of mobile email is read on an iOS device. iOS devices use the Webkit rendering engine, which means they can display really nice-looking HTML emails.

Our friends at Panic (the creators of such popular Mac titles as Coda and Transmit) were well aware of this when they got started on their email announcements. As purveyors of Mac software, they can pretty much always count on their emails being read in Webkit-powered email clients like Apple Mail and the iPhone. As a result, they’ve been able to pull a lot of CSS3 trickery out of the toolbox, including border-radius and text-shadow:

Panic’s email newsletter

But what really impressed me was their use of CSS3 animation. Check out the mesmerizing glowing button effect in this video:

 

To sate your curiosity, here’s the code they used to achieve this effect:

-webkit-animation-name: 'glow';
-webkit-animation-duration: .7s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease-in-out;

And you thought HTML email was a boring medium? Well, to temper things a bit, CSS3 still has very limited support beyond a handful of Webkit-powered email clients, so use it with discretion. But with that in mind, let’s look at Panic’s newsletter again, this time on the iPhone. For comparison, here it is both with and without a @media query (which calls the mobile style sheet):

Let’s now look at how you can optimize your email newsletters for small displays as well.

Inside An HTML Email Builder’s Toolkit

Before we go charging in and dropping @media queries by the dozen, let’s make sure we have the tools for the job. We’ll need the following:

  • An email marketing service like MailChimp or CampaignMonitor to send HTML email campaigns (you can’t do this from desktop or Web email clients like Gmail — sorry);
  • Code editing software, such as Coda or Dreamweaver;
  • A mobile device to test on (like an iPhone or Google Nexus);
  • A variety of Web and desktop email accounts to test, either set up individually or automated via a service such as Litmus;
  • An intermediate-level understanding of HTML and CSS;
  • A lot of patience.

In addition, you’ll need a way to move your CSS inline, for the benefit of clients like Gmail, which strip out the head section of HTML email code. Many email marketing apps can do this automatically when you import your campaign, but if yours doesn’t, then you can use a service like Premailer or MailChimp’s Automatic CSS Inliner Tool for the job. Note that Premailer currently strips out @media queries, so you’ll have to paste them back in prior to testing your design.

Now that you’re armed and dangerous, let’s launch into the theory and code behind mobile email design.

Using CSS To Optimize Your Email For Mobile Devices

If you’ve created mobile style sheets for the Web or have read into responsive design, then you probably know a bit about @media queries. If not, then here’s the skinny: they allow you to provide targeted CSS style sheets that are triggered when a device’s capabilities match specific criteria. For example, you could use a media query to specify that a couple of lines of CSS be applied exclusively to devices with a display width of up to 480 pixels, in order to make your website or email easier to read on these screens.

The following is a snippet of code from the earlier newsletter, telling mobile email clients and browsers to scale down the width of the email layout to 300/325 pixels wide, so that it fits comfortably on displays that are no wider than 480 pixels (i.e. the width of an iPhone in landscape mode):

@media only screen and (max-device-width: 480px) {
   …
   table[class=table], td[class=cell] { width: 300px !important; }
   table[class=promotable], td[class=promocell] { width: 325px !important; }
   …
}

Note how we’re using attribute selectors here. This is to prevent Yahoo! Mail Beta from accidentally calling this style sheet.

One thing to note at this point is that, while you can shrink the dimensions of a design (or hide bits, as we’ll do later) using an @media query, the user will still be downloading all of the content. Adding mobile-specific styles shouldn’t be confused with providing a slimmer or faster-loading version of your content. Mobile-specific styles just make the content easier to read.

The great news is that mobile email clients such as iOS Mail and Android’s default mail client follow @media queries to the letter. So, for example, you could pop one into a style sheet in the head of your HTML email code to transform the design into an easily readable, mobile-friendly layout like the one pictured above. You can also do things like shrink the dimensions of images, and use display: none to hide visual elements that don’t work on small screens. We’ll be using the latter CSS property in the tutorial below to make a lot of email content fit into a very small space.

Using Progressive Disclosure To Shrink Content On Mobile Devices

Now that you have the fundamentals of developing mobile-friendly email designs down pat, let’s learn about an advanced mobile email design technique called progressive disclosure. This involves hiding content behind an interactive element, such as a button or link, and then displaying it on click (or tap). In the context of mobile email, the content might be paragraphs of text that require a lot of scrolling — which, you may know from personal experience, is hard to do. Here is an email design with multiple articles:

The problem here is that even if the email design is optimized for mobile, only the first article will be visible without scrolling. So, if you want your readers to know that there are two or more articles, you could apply progressive disclosure. After all, the mobile version of Wikipedia uses it, and a lot of mobile apps use it, so why not apply it to email?

First, here’s a shot of what we’re going to achieve on mobile devices:

Notice how the articles are shown and hidden using a toggle button? To achieve this, let’s walk through some fairly straightforward code. First, there’s the code for the individual articles:

<td>
   <h4><a href="http://yourdomain.com">First heading</a></strong></h4>
   <a href="#">Hide</a> <a href="#">Show</a>
   <div>
      <p>
         <img src="kitten.jpg" style="float: left;" >Pellentesque habitant morbi…
      </p>
      <a href="http://yourdomain.com">Read more…</a>
   </div>
</td>

Take note of the classes mobilehide, mobileshow and article. These will be handling most of the action.

Then, in a regular CSS style sheet (i.e. one not enclosed by a @media query), we’ll use display: none to hide our show/hide button in desktop and Web email clients. Here’s the code snippet for that:

a.mobileshow, .mobilehide {
display: none;
color: #fff;
}

Yes, so we’ve had to “white them out” for the benefit of Gmail and Android Gmail, which don’t support display: none. Thankfully, the buttons are unresponsive in those clients.

Finally, onto the mobile-specific CSS in the @media query, which I’m sure you’ve been waiting for. Here, we’ll style the show/hide buttons and handle the swapping of states when the show/hide button is tapped:

@media only screen and (max-device-width: 480px) {
   …
    a[class="mobileshow"], a[class="mobilehide"] {
      display: block !important;
      color: #fff !important;
      background-color: #aaa;
      border-radius: 20px;
      -webkit-border-radius: 20px;
      -moz-border-radius: 20px;
      padding: 0 8px;
      text-decoration: none;
      font-weight: bold;
      font-family: "Helvetica Neue", Helvetica, sans-serif;
      font-size: 11px;
      position: absolute;
      top: 25px;
      right: 10px;
      text-align: center;
      width: 40px;
   }
   div[class="article"] {
      display: none;
   }
   a.mobileshow:hover {
      visibility: hidden;
   }
   .mobileshow:hover + .article {
      display: inline !important;
   }
   …
}

With this added to your HTML email code, you should be able to toggle the display of articles in your email design by tapping the show/hide button, like so:

Despite the imperfections in this implementation of progressive disclosure, we’ve found that this technique works like a charm in iPhone Mail and Android Mail. In mobile clients that don’t play so nice with CSS and @media queries (i.e. Android Gmail, BlackBerry and Windows Mobile 7), the text will display, but the show/hide button conveniently does not. For more detailed information on using progressive disclosure, CampaignMonitor’s article “Optimizing HTML Email for Mobile Using Progressive Disclosure” is well worth a read.

Well, that’s enough information on mobile email design to elevate you to black-belt status. For a more hands-on look at mobile email design, I highly recommend the tutorial, “Make Your HTML Email 5× More Mobile-Friendly.” And read “Mobile Email Design in Practice” to get started downloading a mobile-optimized template.

What’s Next For HTML Email Designers?

So, while CSS-unfriendly desktop clients and Web email clients like Gmail will always be here to rain on our parade, the good news is that the rise of mobile email has meant that we may soon be at liberty to create more Web-like email experiences. It has also meant that optimizing your newsletters for handheld and touch displays has gone from being a “nice thing to have” to a given. This doesn’t just affect email newsletters at the code level, but it also changes the way we display design elements. For example, in the following two mobile designs, which do you think is the more effective call-to-action (CTA) button?

Call to action buttons on a small screen

Or consider the CTA in the following mobile-friendly email. If it’s not visible “above the fold,” as they say, then will it be seen at all? Or worse, will recipients end up accidentally tapping the toolbar instead?

CTA is obscured by the toolbar

If designers aren’t asking these questions, they sure will be soon. You need only visit Style Campaign’s blog (which provided the examples above) to grasp the importance of solid mobile design.

Here are a few other important things to consider when designing adaptive layouts:

  • Single-column layouts that are no wider than 500 to 600 pixels work best on mobile devices. They’re easier to read, and if they fall apart, they’ll do so more gracefully.
  • Links and buttons should have a minimum target area of 44 × 44 pixels, as per Apple guidelines. Nothing sucks more than clouds of tiny links on touchscreen devices.
  • The minimum font size displayed on iPhones is 13 pixels. Keep this in mind when styling text, because anything smaller will be upscaled and could break your layout. Alternatively, you could override this behavior in your style sheet.
  • More than ever, keep your message concise, and place all important design elements in the upper portion of the email, if possible. Scrolling for miles is much harder on a touchscreen than with a mouse.

Now it’s your turn to design wicked HTML email newsletters that, with a dash of CSS, look just as effective on the small screen as they do in your Web browser or desktop inbox. I have no doubt that your readers will appreciate the effort.


Newsletter Signup

free SEO Report

Find us on Facebook

Twitter

© 2012 Elite Blog.