Rendering HTML template in Email clients - html

I have HTML template completely written with div, a, img, button elements with inline CSS styling. It renders perfectly in HTML editors but not in Email clients. Should it be completely written in table form for Email clients? Here is my code:
Look it on JSFiddle

I believe your particular question is dependent on which email-client you are targeting. It would be helpful if you could specify which email-client you are looking to use, as well as which parts of your html are not working, because certain email-clients may not support certain parts of your code.
For example, as defined here,
Outlook has the following problems for rendering HTML:
Outlook does not “understand” HTML bulleted list tags
Outlook uses Times New Roman as the default font
Outlook may add a page break to an email if it exceeds 1800px
Outlook cleans up paragraph and margin spacing
Outlook does not support background images
Which you may be able to fix by using specific techniques, such as, as you mentioned, wrapping with tables. I found a link here that may be helpful if you are trying to resolve the rendering on Outlook.
If there is another specific email-client you need to target, there should be posts on stack overflow or on the web for resolving them as well.
Good luck!

You do have to use tables in email HTML and then use CSS and formatting to mask it. Here's a handy guide you can use for email HTML.

Related

Minimize styling for html tables

I am working on HTML Emails and facing one issue, I have style tags defined in the section.
Outlook displays this email message with the required styling but Gmail doesn’t. This is because Gmail’s Preprocessor removes the styles contained in section.
Seems Inline styling is the only option to work with Gmail but it is not affordable because I require css styles applied to and and I have about 9000 table rows, 6-7 columns. So bunch of extra text will get generated if I go for inline styling with might exceed the size limit of email clients. Is there a way to figure out how can we achieve both i.e. not exceeding the size as well as proper rendering of message in Gmail.
Inline styles are the only option for Gmail.
Have a look here: https://www.campaignmonitor.com/css/
This is also a good resource: https://litmus.com/blog/understanding-gmail-and-css-part-1
As noted there:
Commonly stripped elements include JavaScript, object and embed tags,
and Flash. Gmail goes one step further and strips out both the head
and body tags, as well as any style tags in an email.
and:
The quickest way to insure your email campaign renders properly in
Gmail is to place your most important styles inline.

How do I merge 2 HTML documents and their styles correctly?

I'm the author of an email client and one of things I'm in the process of doing is adding support for HTML editing. The editor itself it build upon a HTML rendering control that I've written from scratch, however it supports most HTML and CSS fairly well. The issue I'm having is formatting the reply to HTML email with the user's reply template, which is also HTML (with a different style sheet). So cleanly merging two HTML documents with their own styles without either of them being messed up by the other document's styles.
When the user replies to a HTML email, I parse out the content of the tag and put it into a that forms part of the reply. That div's style shows a line down the left margin to inform the user that it's quoting the original email. Gmail does the same thing. Anyway the styles from the HTML block as saved separately and then insert into the head part of the new document.
What happens of course is that if the original email defined a style for say a link, that style affects all the links outside the original quoted area. So things like my signature at the bottom and the From/To header rendering that is part of the reply template all get that styling from the source HTML.
I'm wondering if there is an easy straight forward solution to containing all the original styles to just the quoted part of the document? Something like namespacing? Or limited scope styling?
The solution I've come to is to add all the incoming styles from the multiple documents to a global style sheet. Styles are matched by first checking the count of properties is the same, then enumerating each property and comparing it's value. This basically gives the software a minimum number of styles to correctly render the content. It could be really slow in a pathological case but so far it's working well in practice.
As an aside, recently I've noticed a lot of email clients striping all the style out of replies. Which to be honest seems like the cheap and nasty solution to the issue. Even if it does give a consistent look.

css style and inline style not working in outlook 2007

I have a html newsletter page. I need to send it to the given mail id. In Outlook , I'm unable to see the my styled html page but in browser css and inline style works perfectly. So why in Outlook does not work inline or Css style?
To get good cross-compatibility it's wise to go with last centuries web practices.
Use tables for structure, style inline, use pixel measurements and be prepared for images to fail.
These basics provide robust results in most clients.
Its best to also avoid background images since these wont work either in outlook.

Shorthand CSS on html emails possible?

I am wondering if shorthand CSS coding is allowed for HTML Emails.
I know the CSS allowed is very limited but I know padding for example is allowed but would this be allowed:
padding:0 4px 0 6px;
The CSS that is allowed in an email is what the receiving email client understands. There are many different email clients. Not all of them even render HTML email (though virtually all do these days), but even where they do render HTML, their rendering engines will all be different from one another, in the same way as web browsers. But unlike web browsers, people don't always change their email client if they're not happy with the way it renders.
So you should expect your email to be read using virtually any kind of email program, including ones which don't render HTML at all, and those which render it, but using an IE4-vintage rendering engine.
That said, I would expect virtually all email clients to correctly interpret the CSS padding style.
You may get some with quirks-mode box models, which will cause your box sizes and positions to be wrong, but they should still interpret the padding correctly within their own set of rules.
One thing I would say is that you should ensure all your CSS code is embedded in the HTML. Put a big <style> tag at the top of your document, rather than a <link> tag with an external reference. The reason for this is that 1) some users may view your email when they're offline, in which case they won't be able to load an external stylesheet, and 2) some email clients may be set to block loading external files from within an email for security reasons, even if the user is online. If your styles are all included in the main body of the email, this won't be a problem. (you may still have the same issue with graphics, but that's a whole different topic of discussion)
I have never had a problem doing 'shorthand' like that, so long as all of the values are provided.
Technically, padding:0px 4px; should work such that top & bottom are 0, and left & right are 4, but not all email clients will honor that (I'm talking to you, Outlook 2007/2010!) so you need to include all four for margin, padding, border etc.
In case this is still of interest I have been looking into this lately. Some mass mail company clearly state that some applications like font (at least) are not rendered well on some email clients.
http://www.campaignmonitor.com/resources/will-it-work/guidelines/
Actually after reviewing a few email sources of templates (Mailchimp, Campaign Monitor, etc) they all consistently avoid them so my conclusion so far is been to do so as well.
In any case more important than shorthand or not is the fact that most CSS styles need to get "inline" of elements as many (Gmail included) ignores them if defined on the head.
As a simple solution I tend to use basic styles on the body element and on a containing table surrounding the content (as body styles also get removed by some clients).
In a simplest form you can set styling for each element like this:
<p style="padding:0 4px 0 6px;">your contents</p>
Yes.
And, as with any "webpage", what the user actually sees is completely up to the "browser" (or HTML-capable email client).
You could have simply tried it to find out.
Also, I recommend not being obnoxious by splashing graphics and colours all over emails. :(

Best way to display a web page within a web page?

I'm writing a webmail product and some emails have body css that changes the background ... so when I Html.Decode() that emailbody, it's altering the CSS of the entire page.
Is there a good way to contain that problem?
You can make your CSS more specific than the email's rules. For example:
body.body is more specific than .body or body
Any styles in body.body that clash with those in the lesser examples above, will override. But to stop the styles merging together, you'll need to define every single style.
Alternatively you can go with rewriting the CSS in the emails, which is the way most webmail/desktop email clients go these days, one way or the other. If you prefix all the rules with #emailMessage, for example, and place the email inside a <div id="emailMessage"></div> tag, all the styles in the email will only apply inside that namespace.
Using an iframe to display emails only introduces more problems based around accessibility, etc etc. Good luck.
The answer to your question is probably "iframe", but in your specific situation, writing a webmail client is going to introduce you to a wonderful new hell called "stripping css from possibly extremely invalid html generated by a large variety of clients that all have their own ideas about what kind of html should be allowed in an email".
Good luck!
A common way is to use iframe, although i'm not sure this is applicable for your problem.
Basically it loads a different html page inside another page. Which makes it independent, but it does mean you have 2 pages to display one email.
http://www.w3schools.com/TAGS/tag_iframe.asp