クイックリファレンス

HTML メールテンプレート チートシート

HTML メールコーディングのリファレンス:テーブルレイアウト、Outlook や Gmail の互換性の落とし穴、非対応 CSS セレクタ、レスポンシブ手法。

· 公開日

HTML メールの開発では、PC やモバイルの各種メールクライアント(Outlook、Gmail、Apple Mail 等)で崩れず表示させるため、テーブルレイアウトによる堅牢な実装が必須です。

クライアントの落とし穴と禁止 CSS

避けるべき CSS プロパティ

プロパティと対象 問題が発生するクライアント 安全な代替手法
p または div に対する width Microsoft Outlook td 要素に width を指定する
p または div に対する padding Microsoft Outlook td セルに padding を適用する
margin (すべての指定) Outlook, Hotmail 余白用テーブルセルを使用する
background-image Outlook Windows desktop Microsoft VML タグを使用する
data-uri 画像 Webmail clients 外部の HTTPS 対応 CDN で画像を配信する

避けるべき CSS セレクタ

セレクタの種別 問題が発生するクライアント
疑似要素 (::before, ::after) Outlook, Yahoo, Gmail
隣接・直下セレクタ (E + F, E > F) Outlook, Gmail App
属性セレクタ ([href^="https"]) 古い Web メールクライアント

鉄則: すべての CSS スタイルは、テーブルセル td の style="..." 属性内にインラインで直接記述してください。

レスポンシブ HTML メールの基本骨格

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Responsive Email</title>
  <style type="text/css">
    @media only screen and (max-width: 600px) {
      .container { width: 100% !important; }
    }
  </style>
</head>
<body style="margin: 0; padding: 0;">
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td align="center" style="padding: 20px 0;">
        <table class="container" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;">
          <tr>
            <td style="color: #333333; font-family: Arial, sans-serif; font-size: 16px; line-height: 24px;">
              メール本文のコンテンツをここに記述します。
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>

関連リファレンス

関連テーマ