Explain Codes LogoExplain Codes Logo

Styling HTML email for Gmail

html
responsive-design
email-design
css
Nikita BarsukovbyNikita Barsukov·Oct 17, 2024
TLDR

When designing HTML emails for Gmail, inline CSS and table layouts are the MVPs. Unlike Fashion Week, in the Gmail world, styles in <head> or <style> tags often go unnoticed. The same goes for the cool kids on the block, Flexbox or Grid - Gmail just doesn't get them. So, what's left is a focus on 'old school' tables for structure and sticking to simple, clean designs because, let's face it, complex CSS can break a fashion show in Gmail's eyes.

Let's take a look at a simple yet elegant example outfitted with important inline CSS:

<table> <tr> <!-- Because everyone needs a stylish header --> <td style="background: #4CAF50; color: white; padding: 10px;"> Styled header </td> </tr> <tr> <!-- Not every day is a red-carpet event. Let's go casual with some light padding --> <td style="padding: 20px;"> Email content </td> </tr> </table>

With a strict focus on inline styling and tables, we ensure our HTML emails don't lose their appeal when they hit the Gmail runway.

All about compatibility and responsiveness

The Gmail fashion circuit is a bit more forgiving after 2016, allowing a bit of finesse with media queries and class selectors. Still, to ensure your email fits all shapes and sizes, inline styles are your best bet. Think of tools like Premailer as your fashion assistant — they transform your grand, document-level CSS visions into practical, Gmail-compatible inline styles, while also validating your CSS to avoid any embarrassing wardrobe malfunctions.

In the choice of fonts, stick with web-safe classics like Arial, Tahoma, or sans-serif to ensure you look good on all devices. Microsoft Outlook requires a bit more attention (it's just high-maintenance that way). To cater to this diva, use conditional comments. Remember, every outfit (or email, in this context) has a weight. Over-accessorizing with too much CSS could slow down your email's loading speed.

Testing and cleaning up

It's always wise to throw on your stunners and check yourself out in the mirror before hitting the ramp. This means using email testing services like Litmus to ensure your HTML email will strut just right in Gmail and other clients. Cleanup your CSS wardrobe — toss out anything unused, and stick to pieces that actually make a difference.

You don't need to memorize the entire Gmail CSS Support documentation, but knowing what's in your toolbox and what's not (like your forgotten tie) can save you design hours.

Tools that work like magic

Some really handy tools and services can help you design emails faster:

  • Premailer: Like a fashion critique to highlight and fix potential mismatches in your email.
  • MailChimp and Mandrill: Think of them as stylists who are perfect for fashion amateurs to learn and create stunning email designs.
  • MJML: This is the Dolce & Gabbana of email designing frameworks. It ensures your design is tailored to fit all email clients beautifully.

Keep improving and adapting to changes

Remember, fashion is an ever-evolving industry. Similarly, email clients update their CSS rendering capabilities from time to time. Stay updated with the latest trends and keep adapting and experimenting to deliver the best experience, even when using XML elements and Outlook's conditional comments.