gmail html preview removes css rule with page-break property - html

we are sending html page as attachment to our users which they can use to print. When you view the html page using gmail in browser it removes any css rule with page-break-after property.
We want to force page-break for printing.
What is the work around for this.

Nothing you can do about it. As explained by chipcullen Gmail strips out all CSS in webpage except the one inside the HTML tags, and even with those it does strange stuff like removing the page-break-after attributes.
The only workaround I can think about is to keep the html file or your server and simply send a link to it in your mail message in place of the attachement.
Great is the mistery surrounding these type of decisions made by Google engineers.
Maybe they want users to go back using Outlook. Well, they almost convinced me.

I can't say about the page-break-after property specifically, but I do know that Gmail does WEIRD things to CSS in HTML emails. For instance, Gmail will strip out any CSS that is either in the <head> or inline with the <body> tag. You will have to apply your rule inline.
From what it sounds like, you're relying more on the browser to render the attachment, and the user is printing from there. Are you sure page-break-after is supported in your test browser?

Related

Rendering HTML template in Email clients

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.

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.

Is safe to put html style tag into body tags coding html emails?

I am coding a html email template. All my code is inline. There are media queries between <style> tag inside the <head> tag.
Can I put the <style> tag inside the <body> tag?
Would that work with all major email clients?
Style tag inside the body has almost identical compatability to a style tag in the head. Each client offers different quirks with this, so overall I would recommend using style in head unless you are unable to.
For example Gmail will strip the style tag regardless where you put it. Your best bet is to test continuously using a service like Litmus or Email on Acid.
Good reference for CSS compatability in email is https://www.campaignmonitor.com/css/
It seems client dependent. Check out a similar answer here.
Some clients will support the use of styling in the body, but generally not in the head. Since there is really no way to incorporate css, it makes sense that this would be the case.

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.

Prevent html emails with Style element from affecting entire web page

We have an single-page web app that displays emails. Some of the emails we're viewing contain style elements that, when loaded into the DOM, affect our entire app. What's the best way to prevent this from happening? I'm currently removing style elements using the HtmlAgilityPack as shown in the post below, but I'm wondering if there's an easier way.
Regex to remove body tag attributes (C#)
Use iframes. That will put the message into a separate document, and there will be no styling interference.
Since you said html emails, the only way to make the Css work is to give inline css style's. External CSS will never work on html mails.