Email HTML - 最佳实践


目录

概述

电子邮件的设计和开发需要一种与传统 Web 开发不同的方法。本指南概述了确保您的 HTML 电子邮件在所有主要电子邮件客户端中正确显示的最佳实践。

关键原则

HTML

使用较旧、更简单的 HTML 标准

表格作为基础

<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr">
        <td align="center" valign="top">
            <!-- 内容在此处 -->
        </td>
    </tr>
</table>

避免使用有问题的元素

CSS

CSS 支持限制

始终使用内联样式

<p style="font-family: Arial, sans-serif; font-size: 16px; line-height: 24px; color: #333333;">
    您的内容在此处
</p>

谨慎使用 style 标签

支持的和不支持的 CSS

支持良好:

支持较差或不一致:

布局技巧

单列设计

使用表格的多列布局

<table border="0" cellpadding="0" cellspacing="0" width="600">
    <tr>
        <td width="300" valign="top">
            <!-- Column 1 content -->
        </td>
        <td width="300" valign="top">
            <!-- Column 2 content -->
        </td>
    </tr>
</table

列堆叠技术

<!--[if mso]>
<table border="0" cellpadding="0" cellspacing="0" width="600">
<tr><td width="300" valign="top"><![endif]-->
<div style="display: inline-block; width: 300px; vertical-align: top;">
    <!-- Column 1 content -->
</div>
<!--[if mso]></td><td width="300" valign="top"><![endif]-->
<div style="display: inline-block; width: 300px; vertical-align: top;">
    <!-- Column 2 content -->
</div>
<!--[if mso]></td></tr></table><![endif]-->

响应式设计

移动优先策略

媒体查询

支持有限但重要:

<style type="text/css">
    @media screen and (max-width: 480px) {
        .mobile-full-width {
            width: 100% !important;
            height: auto !important;
        }
        
        .mobile-font {
            font-size: 16px !important;
        }
    }
</style>

流式混合方法

使用max-width和MSO条件,可在支持和不支持媒体查询的客户端上工作:

<!--[if mso]>
<table width="600" cellpadding="0" cellspacing="0" border="0"><tr><td>
<![endif]-->
<div style="width:100%; max-width:600px; margin:0 auto;">
    <!-- Content -->
</div>
<!--[if mso]>
</td></tr></table>
<![endif]-->

排版

邮件安全字体

始终使用包含广泛支持的字体的字体堆栈:

font-family: Arial, Helvetica, sans-serif;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: 'Times New Roman', Times, serif;
font-family: Verdana, Geneva, sans-serif;
font-family: Georgia, Times, 'Times New Roman', serif;
font-family: 'Courier New', Courier, monospace;

Web 字体

<style>
    @import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');
</style>

<p style="font-family: 'Open Sans', Arial, sans-serif;">您的文本</p>

文本格式最佳实践

图像

图像指南

<img src="https://example.com/image.jpg" alt="图像描述" width="600" height="400" style="display: block; width: 100%; max-width: 600px; height: auto;" border="0">

背景图像

支持有限;始终提供备用背景颜色:

<table background="https://example.com/bg.jpg" bgcolor="#f7f7f7" width="600" cellpadding="0" cellspacing="0" border="0">
    <tr">
        <td">
            内容
        </td>
    </tr>
</table>

电子邮件客户端特定设置

Outlook (Windows)

<!--[if mso]>
    Outlook 相关的代码
<![endif]-->

Gmail

Apple Mail/iOS

可访问性

语义结构

<table role="presentation" border="0" cellpadding="0" cellspacing="0">

文本替代

颜色和对比度

导航和链接

测试工具和服务


版本号 #2
由 壳壳虫 创建于 2026-03-09 11:53:58 UTC
由 壳壳虫 更新于 2026-03-09 11:53:58 UTC