Blog


Repurpose your Images for Mobile Email

10.19.2011

Read More Design Emails for Mobile Devices

Get connected with Email on Acid for up-to-date news and information on the subject of email design, development, and testing!

Email Testing RSS Feed Email Test on Twitter Email Preview on Digg Email CSS on Linked In Email Simulator on Stumbled Upon

Email Testing RSS Feed Email Test on Twitter Email Preview on Digg Email CSS on Linked In Email Simulator on Stumbled Upon

By John Thies
February 10, 2011
 
 
 

The Android Mail App and CSS “Class” Declarations

While testing the native Android email application we found that it does not support embedded or linked CSS class declarations. For example, the following CSS declaration will not be displayed within the mail application:

.test { background-color: red}

This may not be a major issue since its better to use inline CSS wherever possible but we found a work around just in case you have no choice but to use some embedded CSS in your HTML email.

We discovered this solution while testing the @media query support on the Android device. As it turns out - if you wrap a CSS class declaration within a "@media all" block it will render the CSS. Here is an example:

@media all { .test {background-color: red; } }

The great thing about this work-around is that the "@media all" CSS block is supported in every email client that currently supports embedded CSS (argh Gmail!). To get the best intended display results, wrap all of your embedded class declarations within a @media query block.

I also tested this fix for linked CSS. Although linked style sheets are not recommended for all email clients, it will work for the native Android email application. All you need to do is include the "media" attribute with a value of "all" like this example:

<link rel="stylesheet" media="all" href="http://www.domain.com/example.css" />

So from now on remember to wrap all your embedded CSS within a media query block (@media all) and include the "media" attribute in linked CSS tags. That way all of your CSS class declarations will be rendered, barring you don't have any unsupported CSS properties within the declaration.

 

Comments

I'm trying to test this, and also in conjunction with your recent post on media queries in mobile HTML clients (http://www.emailonacid.com/blog/details/C6/media_queries_in_html_emails).

I'm not having much luck. I'm trying to show/hide desktop and smartphone versions of content using these things, and this code doesn't work for me in Gmail web, Gmail Android, or the Android Email client:

<style type="text/css">
@media all {
p#desktop {display:none !important;}
p#smartphone {display:block !important;}
}
</style>

Combining it with a media query, then, also did not work:

<style type="text/css">
@media all and (max-device-width: 480px) {
p#desktop {display:none !important;}
p#smartphone {display:block !important;}
}
</style>

In Android Email, I see nothing (even without those styles) making me think my company's HTML email is just bad on the Android client.

In Gmail on web and the Android Gmail client, those rules appear to just be ignored.

Any thoughts? See anything I'm doing wrong there?

Porter
By Porter on 03/22/2011

Hey Porter, Gmail does not support any embedded CSS styles so the @media trick will not work for any Gmail clients.

As far as the Android device, you might want to run some simple tests to make sure it supports what you are trying to do with the CSS styles.
By John Thies on 03/23/2011

John, thanks.

Ultimately, what I'm after is being able to deliver a desktop-optimized HTML email that also has mobile content in it, and have the mobile client hide the desktop content and show the mobile content - at least for iPhone and Android.

Still hacking away, but not looking good, or at least not crystal clear.
By Porter on 03/23/2011

What a frankly amazing piece.
By Dripable Service on 11/03/2011

You are totally right on this blog post!!
By Tutorial Autoblog Blogspot on 11/14/2011

You are quite correct on this writing!!!
By murah on 11/20/2011

I am in accordance completely...
By venezia on 12/06/2011

Very instructional blog!!
By Hit Promotional Products on 12/17/2011

Share Your Comment

Name:
Email:
Location:
URL:

Comment:

Remember my personal information
Notify me of follow-up comments?

Please enter the word you see in the image below:



Share/Save/Bookmark

If you haven't signed up yet, give our FREE online Email Test a try. Just drop in your code and we will instantly simulate your email in the most popular email clients!

Get connected with Email on Acid for up-to-date news and information on the subject of email design, development, and testing!

Email Testing RSS Feed Email Test on Twitter Email Preview on Digg Email CSS on Linked In Email Simulator on Stumbled Upon

Follow us on Twitter Become a Friend on Facebook Subscribe to our Blog Digg Us! Recommend on StumbleUpon