CSS padding is not working as expected in Outlook
Stefan Bogdanescu
Founder & Senior Architect
Decoding Email CSS Failures: Why Padding Breaks in Outlook
As developers working with responsive design, we often assume that if our CSS works perfectly in modern browsers like Chrome or Firefox, it will render identically everywhere. However, when dealing with email templates, this assumption quickly breaks down. The notorious inconsistency between Gmail’s rendering engine and Microsoft Outlook’s legacy rendering engine frequently causes layout failures, especially concerning spacing properties like padding.
This post dives into why your CSS padding might vanish in Outlook, analyzes the provided HTML snippet, and provides robust solutions for creating email templates that look consistent across all major clients.
The Mystery of Inconsistent Rendering
The issue you are encountering is a classic example of cross-client rendering differences. Webmail services like Gmail use modern rendering engines that interpret CSS properties consistently. Conversely, desktop email clients, particularly older versions of Microsoft Outlook, rely on an older, proprietary rendering engine (often based on Microsoft Word rendering technology).
This difference means that how Outlook interprets specific CSS properties—especially those related to spacing and layout within tables—can differ significantly from how a modern browser does. The provided example highlights this perfectly: the visual result in Gmail is correct, but Outlook struggles with the precise application of padding.
Let's examine your code snippet:
<tr 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>
</tr>
In Gmail, the table structure and padding translate smoothly into visual space. In Outlook, this layout often breaks because complex spacing rules applied directly to <td> elements or nested <span> elements are ignored or misinterpreted by the legacy renderer.
The Developer Solution: Embrace Table-Based Layouts
The fundamental rule for robust email development is to stop relying heavily on modern CSS features like Flexbox or complex float layouts within the main body structure. Instead, you must revert to a highly structured, table-based approach, ensuring that spacing is handled explicitly via table properties and inline styles.
1. Inline All Styles (The Email Mandate)
For maximum compatibility in email development, every style must be inlined. This ensures that the client (like Outlook) sees the styling directly on the element rather than trying to parse complex <style> blocks or external stylesheets.
2. Mastering Table Spacing
Instead of relying solely on padding on the table row (<tr>), which can be inconsistent, use the cellpadding attribute on the table itself, or manage spacing strictly through cell padding and borders. For Outlook compatibility, using the deprecated but widely supported cellpadding often provides more reliable results than modern CSS properties for basic component spacing.
Refactored Code Example
Here is how you can refactor your row to ensure better Outlook compatibility by prioritizing table structure:
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#7d9aaa" style="color: #fff; font-size:15px; font-family:Arial, Helvetica, sans-serif;">
<tr>
<!-- The first cell handles the left alignment and internal padding -->
<td style="padding: 12px 0;">
<span style="font-weight: bold; display: block;">Order Confirmation</span>
</td>
<!-- The second cell handles the content, ensuring proper spacing -->
<td style="padding: 12px 35px;">
<span style="font-weight: bold; display: block; width:400px;">Your Confirmation number is {{var order.increment_id}}</span>
</td>
</tr>
</table>
Notice the shift: we are using explicit <table> tags for structure and managing spacing via well-defined <td> padding, which Outlook handles much more reliably than complex CSS positioning on spans within a row. This approach follows best practices for building maintainable systems, much like how you structure data in frameworks like Laravel, ensuring that the output is predictable regardless of the client environment.
Conclusion
The challenge of inconsistent rendering between webmail and desktop clients is a persistent headache in email development. By understanding the limitations of legacy rendering engines like Outlook and adopting a strict, table-centric approach with meticulously inlined styles, you can guarantee a cohesive visual experience for all your users. Always test your templates across various email clients before deployment to ensure that your design remains pixel-perfect, no matter where it lands.