Cerberus Responsive Email Patterns

repository·main·Indexed 26 days ago

https://github.com/emailmonday/cerberus

A 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.

Tokens
5K
Snippets
6
Records
32
Agent score
89%

What's inside cerberus-email

  1. Overview of Cerberus Responsive Email Patterns

    main
    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.
  2. Implement Ghost Tables for Hybrid Email responsiveness in Outlook

    main

    Hybrid design uses inline-block, max-width, and min-width to 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]-->
  3. Accessibility guidelines for emails

    main

    Improve 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. Use aria-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 alt attribute on every image. Use descriptive text for content and an empty alt="" 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.
  4. Implement responsive images in email

    main

    To ensure images scale down proportionately in small viewports, use a responsive approach. This involves setting the width attribute to 100% and using max-width in the inline style attribute to define the intended desktop width. It is also recommended to use height: auto and display: block to prevent unwanted spacing and ensure proper scaling.

    Key Attributes & Styles:

    • src: Must use a full https:// absolute path.
    • border: Always set to 0 to avoid blue outlines on image links.
    • alt: Always include; use alt="" for ornamental images.
    • class="g-img": Recommended for images wider than ~300px to prevent Gmail from displaying a download icon.

    Responsive vs. Static Implementation:

  5. Use Spacers for reliable vertical separation

    main

    While padding (on <td>) and margin (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 &nbsp; 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 &nbsp; from inheriting and adding unintended space.
  6. Implement Dark Mode using prefers-color-scheme

    main

    Cerberus uses the prefers-color-scheme CSS 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 !important to 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>
  7. General principles for responsive email development

    main

    To 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.

  8. HTML and CSS best practices for email rendering

    main

    Follow 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, and color. 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 align attribute for layout. Avoid float, grid, or flexbox as they lack reliable support in Outlook.
    • HTML Attributes: Use attributes like align, valign, height, and width for 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) or rgb() to ensure compatibility with HTML attributes like bgcolor.
    • Preview Text: Always include preview text to control the snippet that appears beneath the subject line in email clients.
  9. Unstyle auto-detected links

    main

    Some 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-links and 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>