Cerberus Responsive Email Patterns
repository·main·Indexed 26 days ago
https://github.com/emailmonday/cerberusA collection of responsive and accessible HTML email patterns and templates designed for high compatibility across various screen sizes and email clients, including Outlook and Gmail. Version 3.3.0 provides three template approaches: cerberus-fluid.html for simple layouts, cerberus-responsive.html for complex layouts using media queries, and cerberus-hybrid.html for clients without media query support. The documentation includes best practices for table-based layouts, inline CSS, image optimization, accessibility guidelines, and VML for background images.
What's inside cerberus-email
- Cerberus provides a set of responsive and accessible email patterns designed to simplify email development. The patterns are compartmentalized into code blocks that can be used, combined, and nested to build complex emails. Each template is annotated and designed for high compatibility across popular email clients.
Remove Dark Mode support
mainTo completely remove dark mode support from a Cerberus template, delete the@media (prefers-color-scheme: dark)block located within the<head>section of the HTML.Implement Ghost Tables for Hybrid Email responsiveness in Outlook
mainHybrid design uses
inline-block,max-width, andmin-widthto stack columns, but Outlook does not support these properties. To prevent layout collapse, wrap your responsive<div>elements in "ghost tables" using MSO tags. The ghost table provides a fixed width that Outlook respects, while other clients use the<div>styling.Example of wrapping a 340px wide container:
<!--[if mso]> <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> <tr> <td width="340"> <![endif]--> <div style="display:inline-block; width:100%; min-width:200px; max-width:340px;"> Outlook can’t render the CSS in this DIV but other email clients can, so we wrap this in a ghost table that replicates the DIV’s desktop style. In this case, a container 340px wide. </div> <!--[if mso]> </td> </tr> </table> <![endif]-->Accessibility guidelines for emails
mainImprove accessibility and avoid spam filters by following these practices:
- Structural Roles: Add
role="presentation"to all layout tables to prevent screen readers from reading structural cell data. Usearia-hidden="true"on purely presentational elements. - Semantic HTML: Use semantic tags like
<p>,<h>,<strong>, and<em>to allow screen readers to navigate content effectively. - Image Alt Text: Include an
altattribute on every image. Use descriptive text for content and an emptyalt=""for decorative images. Avoid leaving it blank, as screen readers may read the filename. - Link Copy: Avoid generic text like "Click Here" or "Learn More". Use descriptive link text to provide context for screen reader users and to help avoid spam filters.
- Plain Text Version: Always create a plain text version of every email to support non-HTML clients, improve deliverability, and assist users with screen magnifiers.
- Structural Roles: Add
Implement responsive images in email
mainTo ensure images scale down proportionately in small viewports, use a responsive approach. This involves setting the
widthattribute to100%and usingmax-widthin the inlinestyleattribute to define the intended desktop width. It is also recommended to useheight: autoanddisplay: blockto prevent unwanted spacing and ensure proper scaling.Key Attributes & Styles:
src: Must use a fullhttps://absolute path.border: Always set to0to avoid blue outlines on image links.alt: Always include; usealt=""for ornamental images.class="g-img": Recommended for images wider than ~300px to prevent Gmail from displaying a download icon.
Responsive vs. Static Implementation:
Use Spacers for reliable vertical separation
mainWhile
padding(on<td>) andmargin(on<h>,<p>, etc.) are preferred for general spacing, they cannot be used reliably to space out<table>or<tr>elements. In these cases, use a spacer<tr>containing a<td>with a specific height.To ensure the spacer works correctly across all clients:
- Use
aria-hidden="true"to hide the spacer content from screen readers. - Include
inside the cell, as some clients collapse the height if the cell is empty. - Apply
style="font-size: 0; line-height: 0px;"to prevent the from inheriting and adding unintended space.
- Use
Implement Dark Mode using prefers-color-scheme
mainCerberus uses the
prefers-color-schemeCSS media feature to detect a user's system theme. To implement dark mode, define utility classes within a@media (prefers-color-scheme: dark)block in the<head>of your email template.Note that dark mode utility classes must be suffixed with
!importantto ensure they successfully override the inline styles typically used in HTML emails.<style> @media (prefers-color-scheme: dark) { .my-class { color: white !important; } } </style> <p style="color: #000000;" class="my-class"> Text that is black in light mode and white in dark mode. </p>Apply Typography with inline CSS
mainSemantic HTML tags like<h>,<p>, and<ul>are safe and accessible for email. However, you must write CSS inline to specify intended styles (like color) and to zero out default browser/client margins and paddings.General principles for responsive email development
mainTo ensure maximum compatibility with email clients like Microsoft Outlook and various Gmail versions, follow these core principles:
- Use CSS2 instead of CSS3.
- Use
<table>elements for layout instead of<div>s. - Use raster images (PNG, JPG, GIF) instead of vector images (SVG).
- Use inline CSS instead of embedded styles or external stylesheets.
Refer to Can I Email? for specific HTML & CSS support details.
Prevent text wrapping with non-breaking spaces
mainUse the non-breaking space entity to prevent specific words from breaking onto multiple lines. This is useful for keeping names together or preventing typographic orphans and widows.HTML and CSS best practices for email rendering
mainFollow these rules to ensure consistent rendering across email clients:
- Table Setup: Always use
<table border="0" cellpadding="0" cellspacing="0" role="presentation">for new tables to prevent unwanted spacing and to instruct screen readers to skip structural tags. - Nesting: Nest tables for finer layout control.
- CSS Inheritance: Do not rely on inheritance. Some Outlook versions reset properties like
font-family,font-size,font-weight,line-height, andcolor. Always place styles directly in the<td>tag rather than<table>or<tr>. - Spacing: Use padding for spacing inside table cells. Use margin for typography (headlines, paragraphs, and lists).
- Layout: Use the
alignattribute for layout. Avoidfloat,grid, orflexboxas they lack reliable support in Outlook. - HTML Attributes: Use attributes like
align,valign,height, andwidthfor styling, as older rendering engines understand them better than CSS. - Colors: Define colors using six-digit hex codes (e.g.,
#ffffff) instead of shorthand (#fff) orrgb()to ensure compatibility with HTML attributes likebgcolor. - Preview Text: Always include preview text to control the snippet that appears beneath the subject line in email clients.
- Table Setup: Always use
Unstyle auto-detected links
mainSome email clients automatically convert text like dates, times, or addresses into hyperlinks. To make these links appear as plain text, wrap the container in a class named
unstyle-auto-detected-linksand include the following styles in your<head>:<style> a[x-apple-data-detectors], /* iOS */ .aBn, /* Gmail */ .unstyle-auto-detected-links a { border-bottom: 0 !important; cursor: default !important; color: inherit !important; text-decoration: none !important; font-size: inherit !important; font-family: inherit !important; font-weight: inherit !important; line-height: inherit !important; } </style>