What could be causing my HTML email to appear distorted when viewed in Gmail?

After spending the last 6 hours tackling this issue, I am still stuck. Despite my extensive googling, it seems that divs are supposed to work in emails post-2017. All the online HTML email testers I have used indicate that my email layout is perfectly fine.

However, when I send the same email through Gmail, it turns out all garbled and messy.

Here is how the HTML appears when rendered in a browser:

https://i.stack.imgur.com/KOmP7.jpg

This is how the HTML looks like when sent via Gmail:

https://i.stack.imgur.com/Y490j.jpg

And here is the HTML code itself:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta
      http-equiv="Content-Type"
      content="text/html charset=UTF-8 width=device-width, initial-scale=1"
      name="viewport"
    />
    <style>
      @media (max-width: 600px) {
        .email-container {
          width: 390px !important;
        }
        .big-divider {
          width: 324px !important;
        }
        h1 {
          font-size: 23px !important;
        }
        .h1-2 {
          margin-bottom: 23px !important;
        }
        .wine-pic {
          width: 324px !important;
          height: 262px !important;
        }
        h2 {
          font-size: 18px !important;
          width: 330px !important;
        }
        .test-promo-box {
          width: 226px !important;
          height: 42px !important;
          margin-bottom: 30px !important;
        }
        .desktop-icons {
          display: none !important;
        }
        .mobile-icons {
          display: block !important;
        }
        .female-founded {
          font-size: 12px !important;
        }
        .last-paragraph {
          width: 324px !important;
        }
      }
    </style>
  </head>
  <body
    style="
      display: flex;
      flex-direction: column;
      align-items: center;
      background-color: wheat;
      font-family: Verdana, Geneva, Tahoma, sans-serif;
    "
  >

...

...
        
        <p style="text-align: center; font-size: 11px">
          DRINK BOXT LLC, 7601 S Congress Ave #150, Austin, TX 78745
        </p>
        <p
          class="last-paragraph"
          style="
            width: 500px;
            text-align: center;
            font-size: 11px;
            margin-bottom: 97px;
          "
        >
          *Offer valid in the form of BOXT gift cards. Redeem up to 12 months of
          BOXT on us. Offer cannot be combined with any other promotion or new
          member offers and discounts, subject to DRINK BOXT, LLC Terms &
          Conditions. Void where prohibited. Subject to DRINK BOXT, LLC Terms &
          Conditions. Members never pay shipping and can pause, change profile
          or cancel at any time. Subscription is ongoing until canceled. Email
          communication is intended for those 21+. Must be 21+ to order and
          receive wine shipment. Void where prohibited. DRINK BOXT, LLC cannot
          ship to AK, AR, DE, HI, IN, MS, RI, UT, WV.
        </p>
      </div>
    </div>
  </body>
</html>

I've attempted various deletions within the code, from removing the entire block to the media queries, but unfortunately, nothing seems to resolve the issue.

If anyone could provide assistance in solving this matter, I would greatly appreciate it.

Answer №1

While <div> elements may function properly in emails, media queries do not work consistently across all email clients. Additionally, properties like display: flex and display: grid will not render correctly either, as most email clients only support HTML 4 standards. For reliable email design patterns, check out the templates available on Cerberus. These templates have been tried and tested for over 5 years and are considered the industry standard. Even Litmus, a prominent email testing company, uses them in their paid email builder

Answer №2

It appears that many CSS features, such as flexbox and grid layouts, are still not fully supported in email clients. However, media queries work well on Gmail.

I found that the best solution for me was to restructure everything using tables, which now works seamlessly.

Below is the table-based code I used:

<html>
  <head>
    <meta
      http-equiv="Content-Type"
      content="text/html charset=UTF-8 width=device-width, initial-scale=1"
      name="viewport"
    />
    <style>
      @media (max-width: 600px) {
        .desktop-icons {
          display: none !important;
        }
        .mobile-icons {
          display: block !important;
        }
        .female-founded {
            font-size: 12px !important;
        }
        .unique-code {
          font-size: 16px !important;
        }
        .last-paragraph {
          font-size: 9.5px !important;
        }
      }
    </style>
  </head>
  <body>
    <div id="email" style="width:600px;margin: auto;background:#FFFCF7; font-family: Verdana, Geneva, Tahoma, sans-serif;">
        <table role="presentation" border="0" align="center" cellspacing="0">
          <tr>
            <td>
              <img style="
                  margin-top: 28px;
                  margin-bottom: 21px;
                  width: 20px;
                  height: 20px;
                " src="https://keen-pike-986d32.netlify.app/images/BOXT_Final_Logo_Black_RGB.png">
            </td>
          </tr>
        </table>
      
        <hr class="big-divider" style="width: 85%; margin-top: 0" />
        <h1 style="text-align: center; font-size: 28px; margin-bottom: 2px">
          HERE'S $10 OFF
        </h1>
        <h1 class="h1-2" style="
                  text-align: center;
                  margin-top: 0;
                  margin-bottom: 16px;
                  font-size: 28px;
                ">
          YOUR FIRST BOXT!
        </h1>
      
        <!-- Header -->
        <table role="presentation" border="0" width="100%" cellspacing="0">
          <tr>
            <td align="center">
              <img class="wine-pic" src="https://keen-pike-986d32.netlify.app/images/wine_box.jpg" style="width: 503px; height: 406px" />
          </tr>
          </td>
        </table>
      
        <!-- Body 1 -->
        <table role="presentation" border="0" width="100%" cellspacing="0">
          <tr>
            <td align="center" style="padding: 15px 30px 10px 15px;">
              <h2 class="unique-code" style="
                  text-align: center;
                  margin-top: 0;
                  margin-bottom: 5px;
                  font-size: 20px;
                  font-weight: 500;
                ">
                Enter the unique code below at
                </h2>
                <h2 class="unique-code" style="
                  text-align: center;
                  margin-top: 0;
                  margin-bottom: 0;
                  font-size: 20px;
                  font-weight: 500;
                ">
                checkout for $10 off your first BOXT.
              </h2>
            </td>
          </tr>
        </table>
      
      <table border="0" width="100%" cellspacing="0">
          <tr>
            <td align="center">
              <div
                class="test-promo-box"
                style="
                  height: 42px;
                  width: 226px;
                  background-color: rgb(146, 191, 197);
                  margin-bottom: 37px;
                "
              >
              <h3 style="text-align: center; font-size: 15px; padding-top: 11px;">TEST PROMO CODE</h3>
              </div>
          </tr>
          </td>
        </table>
      
      <hr class="big-divider" style="width: 85%; margin-top: 0" />
      
        <<!-- Body 2-->
      <div class="desktop-icons">
        <table role="presentation" border="0" width="100%" cellspacing="0">
          <tr>
            <td align="center" style="vertical-align: top;
        padding: 30px 10px 30px 30px;">
              <img
                    style="width: 102px; height: 61px"
                    src="https://keen-pike-986d32.netlify.app/images/img_1.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 30px 10px 30px 30px;">
              <img
                    style="width: 46px; height: 61px"
                    src="https://keen-pike-986d32.netlify.app/images/img_2.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 30px 10px 30px 30px;">
              <img
                    style="width: 51px; height: 61px"
                    src="https://keen-pike-986d32.netlify.app/images/img_3.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 30px 10px 30px 30px;">
              <img
                    style="width: 80px; height: 61px"
                    src="https://keen-pike-986d32.netlify.app/images/img_4.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 30px 10px 30px 30px;">
              <img
                    style="width: 64px; height: 61px"
                    src="https://keen-pike-986d32.netlify.app/images/img_5.png"
                  />
            </td>
          </tr>
        </table>
      
        <table role="presentation" border="0" width="100%" cellspacing="0">
          <tr>
            <td align="center" style="vertical-align: top;
        padding: 10px 10px 30px 90px;">
              <img
                    style="width: 50px; height: 57px"
                    src="https://keen-pike-986d32.netlify.app/images/img_6.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 10px 10px 30px 30px;">
              <img
                    style="width: 74px; height: 58px"
                    src="https://keen-pike-986d32.netlify.app/images/img_7.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 10px 10px 30px 30px;">
              <img
                    style="width: 57px; height: 64px"
                    src="https://keen-pike-986d32.netlify.app/images/img_8.png"
                  />
            </td>
            <td align="center" style="vertical-align: top;
        padding: 10px 90px 30px 30px;">
              <img
                    style="width: 50px; height: 63px"
                    src="https://keen-pike-986d32.netlify.app/images/img_9.png"
                  />
            </td>
          </tr>
        </table>
      </div>
      
      <div class="mobile-icons" style="display: none;">
       <!--Mobile icons here-->
        </div>
      <hr style="width: 63px; margin-top: 0; margin-bottom: 30px" />
      
      <p
                style="
                  margin-bottom: 5px;
                  margin-top: 0;
                  font-size: 13px;
                  text-align: center;
                "
              >
               
              </p>
              <p
                style="
                  margin-top: 0;
                  margin-bottom: 30px;
                  font-size: 13px;
                  text-align: center;
                "
              >
                
              </p>
              

              <h3
                class="female-founded"
                style="
                  font-size: 13.5px;
                  margin-top: 0;
                  margin-bottom: 16px;
                  text-align: center;
                "
              >
                
              </h3>
              <hr
                class="big-divider"
                style="width: 85%; margin-top: 0; margin-bottom: 15px"
              />
          
     <!--table with text info here-->

   
   <!-- closing tags --> 
  </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Animated CSS Checkmark Design

How can I create an animated Check-mark using CSS with SVG animation? I attempted the following code but it doesn't seem to be working. Any suggestions? DEMO: https://jsfiddle.net/b7Ln0jns/ CSS: @import "bourbon"; $color--green: #7ac142; $curve: c ...

`Enhancing the appearance of code in PHP`

I'm struggling with customizing the data pulled from the database. Can anyone provide assistance? I attempted to define $style within the while loop and assign it to $questions, but nothing is displaying on the webpage. While I have some familiarity w ...

How do I create a sliding dropdown notification bar?

Can anyone provide some guidance on how to create a sliding dropdown section for my homepage, similar to the one on this website: . (Please note, be cautious of potential malware) I'm interested in replicating the dropdown section that says "call for ...

Browse through and review all information - utilizing python selenium

I am currently working on a project that involves scrolling and retrieving every post made by users. However, I am facing an issue where my code is only reading 2 or 3 posts before moving on to the next one. I have tried adjusting the sleep() duration, p ...

What is the process to retrieve a variable from a Node.js file in an HTML document?

What is the best way to showcase a variable from a node.js route in an HTML File? I have a node.js route structure as follows: router.post("/login", async (req,res) => { try { const formData = req.body const name = formData.name ...

Attempting to customize react-bootstrap styling within a NextJS application

I'm currently working on a project using Next.js and attempting to integrate Bootstrap as the CSS framework. After installing react-bootstrap into the project, I proceeded to create the navigation bar. My goal is to assign an '.active' class ...

mobile-exclusive wordpress text area problem

There seems to be a padding issue that is only affecting mobile devices. https://i.stack.imgur.com/2Tbuc.png The cause of this problem has been somewhat identified, but the solution isn't clear without impacting the preview on computers. Here is th ...

Aptana Studio 3 fails to detect PHP code embedded within an .html file

When writing code, such as: <!DOCTYPE html> <html> <body> <?php echo "My first PHP script!"; ?> </body> </html> After <?php, I am encountering a red X icon error indicating that a ">" is missing at the end of t ...

Struggling to align the login button accurately within the navbar

For proper alignment, the "Login" button needs to be pushed to the right of the navbar alongside other buttons. To see the issue and the code, check out this JSFiddle example: https://jsfiddle.net/sterlingmd17/tk17zjfq/1/ <nav class="navbar navbar ...

Deciphering the creation process behind the "WhatsApp Web" front-end page

I'm currently exploring the creation process of the front-end page for WhatsApp Web, specifically focusing on the list of contacts located on the left side (<div id="pane-side">). The contact names within this list are identified by the class "e ...

Permitting the inclusion of decimals in the isNaN function

My script currently has the capability to input a number in one textbox and calculate its equivalent in other textboxes. $("input[type=text]").keyup(function () { var number = parseFloat($(this).val()); var inc = parseFloat($(this).attr( ...

Steps for adding a delete icon to a text input field and enabling the functionality to delete text

In the code snippet below, I am creating a text input field: <input type="text" class="signup-input text-value" name="" placeholder="e.g. <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d48554c405d41486d">[email pro ...

The Challenge with jQuery Nano Scroll

I recently added the jQuery Nano Scroll plugin to my HTML page. However, I am facing an issue where the scrollpane is not visible. When I inspect the div using Chrome, the scrollpane appears. Any suggestions on how to resolve this? Here's a snippet ...

How much data is considered a suitable amount to be loaded on a single page?

Currently, I am developing a page for a photographer on the website page. To enhance user experience, I have implemented a jQuery script that allows users to flip through images seamlessly. Initially, I was replacing just the src attribute of each image, b ...

Tips for globally overriding MUIv4 class in JSS for nested themes

Summary: Skip to EDIT2 MUIv4 has generated the following classes for me based on my nested theming: <label class="MuiFormLabel-root-121 MuiInputLabel-root-113 MuiInputLabel-formControl-115 MuiInputLabel-animated-118 MuiInputLabel-shrink-117 M ...

Issue with the Dropdown menu in Metro UI CSS - not functioning properly

I have integrated the METRO UI CSS into my project and created a dropdown menu. The design looks great, but unfortunately, the dropdown list is not appearing as expected. To implement this feature, I followed the example provided on the following link: H ...

Evaluate numerical values using xsl:choose function

Using XSL version 1.0, I am populating an HTML table with percentage values from XML. My goal is to display the highlighted color of the percentages based on a condition, but the condition is not being processed as expected, leading to the exclusion of the ...

Use jQuery to assign a unique CSS class to every third ul element on the page

Currently, I have a large number of li elements that I am iterating through and grouping in sets of 5. However, I need to assign a unique class to every third group in order to achieve the following structure: <ul class="class1"> ...

Creating a loader for a specific component in Angular based on the view

Creating a loader for each component view is crucial when loading data from an API. Here is the current structure of my components within my <app-main></app-main>: <app-banner></app-banner> <app-data></app-data> <app ...