css padding is not working in outlook
Solution 1
I changed to following and it worked for me
<tr>
<td bgcolor="#7d9aaa" style="color: #fff; font-size:15px; font-family:Arial, Helvetica, sans-serif; padding: 12px 2px 12px 0px; ">
<table style="width:620px; border:0; text-align:center;" cellpadding="0" cellspacing="0">
<td style="font-weight: bold;padding-right:160px;color: #fff">Order Confirmation </td>
<td style="font-weight: bold;width:260px;color: #fff">Your Confirmation number is {{var order.increment_id}} </td>
</table>
</td>
</tr>
Update based on Bsalex request what has actually changed. I replaced span tag
<span style="font-weight: bold;padding-right:150px;padding-left: 35px;">Order Confirmation </span>
<span style="font-weight: bold;width:400px;"> Your Confirmation number is {{var order.increment_id}} </span>
with table and td tags as following
<table style="width:620px; border:0; text-align:center;" cellpadding="0" cellspacing="0">
<td style="font-weight: bold;padding-right:160px;color: #fff">Order Confirmation </td>
<td style="font-weight: bold;width:260px;color: #fff">Your Confirmation number is {{var order.increment_id}} </td>
</table>
Solution 2
Unfortunately, when it comes to EDMs (Electronic Direct Mail), Outlook is your worst enemy. Some versions don't respect padding when a cell's content dictates the cell dimensions.
The approach that'll give you the most consistent result across mail clients is to use empty table cells as padding (I know, the horror), but remember to fill those tables with a blank image of the desired dimensions because, you guessed it, some versions of Outlook don't respect height/width declarations of empty cells.
Aren't EDMs fun? (No. They are not.)
Solution 3
Avoid paddings and margins in newsletters, some email clients will ignore this properties.
You can use empty tr
and td
as was suggested (but this will result in a lot of html), or you can use borders with the same border color as the background of the email. so, instead of padding-top: 40px
you can use border-top: 40px solid #ffffff
(assuming that the background color of the email is #ffffff
)
I've tested this solution in gmail (and gmail for business), yahoo mail, outlook web, outlook desktop, thunderbird, apple mail and more. As far as I can tell, border property is pretty safe to use everywhere.
Example:
<!-- With paddings: WON'T WORK IN ALL EMAIL CLIENTS! -->
<table>
<tr>
<td style="padding: 10px 10px 10px 10px">
<!-- Content goes here -->
</td>
</tr>
</table>
<!-- Same result with borders and same border color of the background -->
<table>
<tr>
<td style="border: solid 10px #ffffff">
<!-- Content goes here -->
</td>
</tr>
</table>
<!-- Same result using empty td/tr. (A lot more html than borders, get messy on large emails) -->
<table>
<tr>
<td colspan="3" height="10" style="height: 10px; line-height: 1px"> </td>
</tr>
<tr>
<td width="10" style="width: 10px; line-height: 1px"> </td>
<td><!--Content goes here--></td>
<td width="10" style="width: 10px; line-height: 1px"> </td>
</tr>
<tr>
<td colspan="3" height="10" style="height: 10px; line-height: 1px"> </td>
</tr>
</table>
<!-- With tr/td every property is needed. height must be setted both as attribute and style, same with width, line-height must be setted JIC default value is greater than actual height and without the some email clients won't render the column because is empty. You can remove the colspan and still will work, but is annoying when inspecting the element in browser not to see a perfect square table -->
In addition, here is an excelent guide to make responsive newsletters without mediaqueries. The emails really works everywhere:
And always remember to make styles inline:
To test emails, here is a good resource:
Finally, for doubts about css support in email clients you can go here:
https://templates.mailchimp.com/resources/email-client-css-support/
or here:
https://www.campaignmonitor.com/css/
Solution 4
To create HTML in email template that is emailer/newsletter, padding/margin is not supporting on email clients. You can take 1x1 size of blank gif image and use it.
<tr>
<td align="left" valign="top" style="background-color:#7d9aaa;">
<table width="640" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="left" valign="top" colspan="5"><img style="display:block;" src="images/spacer.gif" width="1" height="10" alt="" /></td>
</tr>
<tr>
<td align="left" valign="top"><img style="display:block;" src="images/spacer.gif" width="20" height="1" alt="" /></td>
<td align="right" valign="top"><font face="arial" color="#ffffff" style="font-size:14px;"><a href="#" style="color:#ffffff; text-decoration:none; cursor:pointer;" target="_blank">Order Confirmation</a></font></td>
<td align="left" valign="top" width="200"><img style="display:block;" src="images/spacer.gif" width="200" height="1" alt="" /></td>
<td align="left" valign="top"><font face="arial" color="#ffffff" style="font-size:14px;">Your Confirmation Number is 260556</font></td>
<td align="left" valign="top"><img style="display:block;" src="images/spacer.gif" width="20" height="1" alt="" /></td>
</tr>
<tr>
<td align="left" valign="top" colspan="5"><img style="display:block;" src="images/spacer.gif" width="1" height="10" alt="" /></td>
</tr>
</table>
</td>
</tr>
Solution 5
Just use
<Table cellpadding="10" ..>
...
</Table>
Don't use px.Works in MS-Outlook.
Mukesh
I am a Magento developer having 9+ years of experience in Magento, Magento2, Php, MySQL development. I have good experience of third party APIs integrations with Magento. I am also one of the Moderator of the Magento Community Forums. Magento Community Forum India
Updated on July 05, 2022Comments
-
Mukesh almost 2 years
I have following html in email template.
I am getting different view in MS Outlook and in gmail for the same.
<tr> <td bgcolor="#7d9aaa" style="color: #fff; font-size:15px; font-family:Arial, Helvetica, sans-serif; padding: 12px 2px 12px 0px; "> <span style="font-weight: bold;padding-right:150px;padding-left: 35px;">Order Confirmation </span> <span style="font-weight: bold;width:400px;"> Your Confirmation number is {{var order.increment_id}} </span></td> </tr>
How to fix this?
-
Mukesh over 10 yearsIn which element I need to use this?
-
Carol McKay over 10 yearsthe span that you are putting the padding in, in fact both spans would be a good idea.
-
monners over 10 yearsActually padding and margin is supported in some email clients
-
John over 10 yearsPadding is supported in all, margin is not supported in some clients (outlook.com, Lotus Notes)
-
Cthulhu over 8 years@John Actually you can use margin in outlook.com if you write it with capital M (
Margin: 10px;
instead ofmargin: 0px;
). -
Cthulhu over 8 years@CarolMcKay
display
won't work in MS Oulook nor Gmail. -
Aur Saraf about 8 yearsHTML email is such a horrible field that I'm not sure if @Cthulhu is trolling here :(
-
Cthulhu about 8 years@AurSaraf Not trolling, just had to code too many e-mails and newsletters. You can test
Margin: 10px;
, it works without issues. Here's a resource: emailonacid.com/blog/article/email-development/… -
JaidynReiman about 8 yearsI just tested this myself, it definitely works. I'm not sure if its the best thing to rely on, its probably something that they'd discover and get rid of later.
-
revelt over 7 years
cellpadding
on<table>
is unreliable, just likecellspacing
. It's best to use padding on<td>
-
revelt over 7 yearsPadding will work on Outlook, provided you follow best practice — nest everything in separate
table
s and/ortd
's (columns). Instead of twospan
's there should be a single table with 2td
's. -
revelt over 7 years@AurSaraf I'm a professional email developer and I can say coding email is easy. Regarding padding/margin — set padding only on
TD
's. Never usemargin
attribute (maybe on media query styles on mobiles, but definitely not for email code part for desktop clients). -
revelt over 7 yearsIt's a bad idea. Use a nested table.
-
godblessstrawberry over 7 yearsthanks for pointing to images, this will definitelly work. btw for those who are looking for proper images - placehold.it is a really good source e.g. placeholdit.imgix.net/…
-
Admin about 7 yearsSince this answer relies on images, what happens when images are blocked? Will red X icons appear in place of those tiny images?
-
GDY over 6 yearsHad to suppres the impulse to vote down on this topic because outlook sucks ... but good answer so +1
-
Ishmael over 6 yearsWhat is an EDM?
-
Karan Chadha about 6 yearsI wish I could do +100. Such problems related to peculiarities of particular product are particularly hard to resolve.
-
Karan Chadha about 6 yearsBTW - I managed to resolve w/o image by using "% width" for td in table
-
niltoid about 6 yearswould be brilliant if it worked - didn't solve on outlook.com
-
Bsalex almost 6 yearsPlease state what has been changed. Don't force users to use diff tools.
-
Craig1123 over 5 years@Ishmael EDM stands for Electronic Direct Mail which utilizes multiple forms of communication to relay and reinforce email campaign messages. digitalthing.com.au/what-are-edms-and-email-marketing-campaigns
-
Nosajimiki about 5 yearsBe careful using image spacers. Many email clients can be set to block images by default which could totally wreck your formating. Generally, your emails should still be readable with all images replaced with missing image tags
-
Matt Cosentino about 5 years@Craig1123 That makes a lot more sense than electronic dance music. ;)
-
OutstandingBill over 4 yearsSeems to work on my version of Outlook. Thanks Jacob!
-
scp over 3 yearsThis worked in Outlook365 when nothing else seemed to
-
Mike about 3 yearsJust tested in Outlook 365 (v16.0.12527), and I found that applying a border to my H2 style like this: h2 { border-top: solid 100px #ffffff; } does add a few pixels border (perhaps 8?) but not the 100px I am specifying. I tried this many times with different values, always the same ~8px border.
-
Nathan over 2 yearsPadding must go on
<td>s
for cross-email compatibility, not<span>s
. -
MadMac over 2 yearsDoes not work in Outlook. Man outlook is a piece of cr@p.