Skip to content
Tutorials Center
My learning

Topics

Lesson 114 of 122 ยท Accessibility and Best Practices

HTML Email Basics

Learn how HTML email differs from web pages. Build table-based layouts, use inline styles, make bulletproof buttons and plan for the limits of email clients.

HTML email looks like a web page, but it lives in a much harsher place. A page you build for browsers can use modern CSS, JavaScript and any layout you like. An email has to survive dozens of email clients (Gmail, Outlook, Apple Mail, mobile apps, webmail in many browsers). Each one rewrites your HTML, strips things out and renders with its own engine. Some are surprisingly old: desktop Outlook for Windows renders emails with the Microsoft Word engine.

The result is a style of HTML that feels like 2003: tables for layout, inline styles and very few fancy features. This lesson explains the rules, the reasons behind them and how to write an email that is still accessible and easy to read.

What email clients do to your HTML

Before you write any code, know what to expect:

  • JavaScript never runs. No scripts, no event handlers, no <form> that works reliably.
  • <style> and <link> support is patchy. Many clients remove <link>, and some strip <style> blocks or ignore parts of them.
  • Inline styles are the most reliable. A style="..." attribute on the element is applied nearly everywhere.
  • Modern layout is risky. Flexbox, Grid, position, CSS variables and many selectors are unsupported in at least one big client.
  • Images may be blocked until the reader clicks "show images". Your email must make sense without them.
  • Dark mode may recolor your email automatically, sometimes with odd results.
flowchart LR
  A["Your HTML"] --> B["Mail server"]
  B --> C["Email client"]
  C --> D["Sanitizes and rewrites"]
  D --> E["Reader sees a version of it"]

Your HTML passes through the client's sanitizer, so the reader may see a different version than you wrote.

Because of this, always test in real clients with a service or by sending test messages to several accounts. The browser preview of your file proves very little.

The skeleton

A solid starting document looks like a normal page with a few extras:

HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="color-scheme" content="light dark">
  <title>March newsletter</title>
</head>
<body style="margin:0; padding:0; background-color:#f1f5f9;">
  <!-- content goes here -->
</body>
</html>
  • Keep lang on <html> and a real <title>. Screen readers and some clients use them.
  • Use <meta charset="utf-8"> and write accented characters or emoji directly, or as entities (see HTML Entities).
  • The viewport meta tag helps clients that scale to the phone screen.

Layout with tables

On a normal web page you should never use tables for layout (see Tables). In email, tables are still the safest layout tool. The pattern:

  1. An outer table 100% wide that carries the page background color.
  2. A centered inner table, usually 600 pixels wide or less, that holds the content.
  3. Rows and cells for each block (header, text, button, footer).

Because the tables are only for layout, tell assistive technology to ignore the table semantics with role="presentation". Also set cellpadding, cellspacing and border explicitly, since clients disagree on the defaults.

A centered 600px email layout

Notice that width="600" plus style="width:100%; max-width:600px" gives a fixed width in old clients and a fluid one in modern ones. Resize the preview and the card shrinks without breaking.

Inline styles

Because <style> blocks are unreliable, put the important styles on each element. Typing that by hand gets tedious, so teams write normal CSS and let a build step or tool inline it before sending.

Rules of thumb:

  • Set font-family, font-size, line-height and color on every cell with text. Inheritance is less dependable than on the web.
  • Use px units. Relative units behave inconsistently.
  • Provide web-safe font stacks such as Arial, Helvetica, sans-serif or Georgia, serif. Custom web fonts load in only a few clients, so treat them as a bonus.
  • Use margin:0 on paragraphs and headings and control spacing with cell padding, which is more reliable than margins.
  • Write colors as six-digit hex values, for example #1e3a8a.
  • You may still keep a <style> block for progressive enhancement, such as @media queries that improve the phone layout. Clients that ignore it still show a fine email.

Bulletproof buttons

A button in email is just a link. Styling an <a> with padding and a background color can fail in Outlook for Windows, where padding on inline elements is ignored. The reliable pattern is a one-cell table with the background on the <td>:

HTML
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td bgcolor="#1d4ed8" style="border-radius:6px;">
      <a href="https://example.com/events"
         style="display:inline-block; padding:12px 24px; font-family:Arial, sans-serif;
                font-size:16px; color:#ffffff; text-decoration:none;">
        See the events
      </a>
    </td>
  </tr>
</table>

The colored <td> is the button's body, so it stays clickable-looking even where the link's own padding is ignored. A text link inside always works, even with images blocked.

Images in email

  • Give every image alt text, and style it so the fallback is readable if images are blocked: style="font-family:Arial,sans-serif; color:#1f2937;" on the <img>.
  • Set width and height attributes in pixels, and add style="display:block; border:0;" to remove odd gaps under images in some clients.
  • Host images on a public HTTPS URL. Reference them with absolute URLs, never relative paths.
  • Use JPEG, PNG or GIF. SVG and WebP are not supported everywhere.
  • Do not put important text only in an image. Many readers never load images.
  • Provide 2x resolution images for sharp screens, displayed at half the pixel size.
An email block with an image and a button

Browsers show SVG, but many email clients do not. The demo uses an SVG only because it is the sample image available in this course. In a real email, export a PNG or JPEG.

Accessibility in email

The rules from Accessibility still apply, and mistakes are easy to make because email is so constrained:

  • Real headings and paragraphs inside table cells, not fake ones made of bold text.
  • Contrast of at least 4.5:1 for body text, remembering that dark mode may invert colors.
  • Readable size: body text of 16px or more, with generous line height.
  • Descriptive link text. "See the events" beats "click here".
  • role="presentation" on layout tables, and no table-based layout headers for real data tables.
  • Plain-text alternative. Send a text/plain part alongside the HTML. It helps readers whose clients prefer text and improves deliverability.
  • Preheader text (the preview line shown after the subject) should say something useful, since many people only see that.

Things to avoid

  • JavaScript, <form>, <video>, <audio>, <iframe> and <object>. Most clients remove or ignore them.
  • Background images as the only carrier of text.
  • position, float (patchy), Flexbox, Grid and CSS variables.
  • Huge messages. Gmail clips emails over about 102 KB of HTML, hiding the rest behind a "View entire message" link, and that can hide your unsubscribe link.
  • Missing unsubscribe links and a sender address. They are required by law in many countries and are a deliverability factor.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why do email developers still use tables for layout?

    Clients such as desktop Outlook ignore or mangle Flexbox and Grid, but render nested tables consistently.
  2. 2. What does role="presentation" on a layout table do?

    The table is only used for layout, so screen readers should not announce rows and columns.
  3. 3. Where should the important styles of an email go?

    External stylesheets and scripts are often removed. Inline styles are applied by almost every client.
  4. 4. Why build a button from a table cell with a background color?

    Outlook for Windows ignores padding on inline elements, so the colored td provides the visible button body.

Summary

  • Email clients rewrite and strip HTML, never run JavaScript and vary widely, so write conservative HTML.
  • Use nested layout tables (with role="presentation"), a fixed or max width of about 600px and explicit cellpadding, cellspacing and border.
  • Put key styles inline, use web-safe fonts and px units, and treat <style> and @media as enhancements.
  • Build buttons as a colored table cell with a link inside.
  • Give images alt, width, height and display:block, use absolute HTTPS URLs and never put essential text only in an image.
  • Keep accessibility basics: contrast, readable size, meaningful links, a plain-text part and an unsubscribe link.
  • Test in real email clients.

Now put everything together in the Personal Profile Page project.