Solved

Can we incorporate CSS in an email send?

  • 10 April 2021
  • 3 replies
  • 83 views

I’m trying to incorporate CSS styling in my email sends but am finding that there is a discrepancy between what I see in the preview, and what users see. Has anyone else had this problem?

Example 1: I am able to set the font of H1 within my <style> tags. Looks great in InSided. Then the email is sent and the font reverts to Times New Roman in Gmail, Yahoo, and Outlook

Example 2: I tried to incorporate collapsible elements in my emails. They look correct in InSided. In Gmail, the styling is completely gone. The check-boxes which were turned into arrows in the CSS turn into the basic check-boxes. 

 

I’m wondering if anyone else has had this problem? Is CSS not allowed in emails?

 

I’m happy to share my code if needed but I’m not a web developer so it’s probably a little ugly. I’m trying to do basic functionality testing before making it look nice. 

 

Edit: I see in the Knowledge base that CSS should technically be possible, so I’m adding my code here for reference. In the image below, you can see the InSided output (top) and what the email looks like in Gmail (bottom). Anyone have any ideas?

 

 

icon

Best answer by Cristina 12 April 2021, 10:52

View original

3 replies

Note: Here is a very very simplified version. Again, the collapsing works on the InSided preview but does not work when the email is received. 

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.collapsibleList li > input + * {
 display: none;
}
 
.collapsibleList li > input:checked + * {
 display: block;
}

.collapsibleList li > input {
 display: none;
}

.collapsibleList label {
 cursor: pointer;
}
</style>
</head>
<body>

<ul class="collapsibleList">
 <li>
  <label for="mylist-node1">Click to open list 1</label>
  <input type="checkbox" id="mylist-node1" />
  <ul>
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
  </ul>
 </li>
 <li>
  <label for="mylist-node2">Click to open list 2</label>
  <input type="checkbox" id="mylist-node2" />
  <ul>
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
  </ul>
 </li>
</ul>

</body>
</html>

 

Badge +1

Hi @alexandra.culler! Thank you for this question and the information you shared! 

Email clients are notoriously picky with what they accept, especially around email styling. For example, <style> tags are mostly a no-go, as most styles have to be inlined. One of our engineers recommended this read around using CSS in HTML emails and this particular one might be useful as you’re using position in the CSS code which seems to be poorly supported. 

For extra design capabilities, the MJML framework might be a cool one to try out. Hope this helps! 

 

Thanks @Cristina! I’ll take a look at these resources 🙂.  

Update: The MJML framework is really cool! Unfortunately my attempts to get a collapsible element will not work, even with this. It appears Gmail restricts the MJML accordion just like it restricts the CSS attempts. Thanks for the guidance, Cristina! The MJML will definitely be useful for other elements, I’m sure ^_^. 

Reply