{"id":3233,"date":"2017-09-19T02:16:27","date_gmt":"2017-09-19T02:16:27","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=3233"},"modified":"2017-09-20T06:41:36","modified_gmt":"2017-09-20T06:41:36","slug":"targeting-new-gmail-css","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/targeting-new-gmail-css\/","title":{"rendered":"Targeting The New Responsive Gmail With CSS [Updated]"},"content":{"rendered":"<p><B>Update 9\/18\/2017:<\/B> <I>Gmail made a change that requires some changes to targeting techniques. See updates below.<\/I><\/p>\n<p>The new Gmail update with <a href=\"https:\/\/www.emailonacid.com\/blog\/article\/industry-news\/gmail-update-embedded-styles-and-media-queries\">responsive email support<\/a> has been a blessing for email designers everywhere. <\/p>\n<p>However the update also creates a few issues for those of us that are interested in pushing the envelope with advanced CSS. This is because it is now harder to use CSS to distinguish Gmail that doesn&#8217;t support advanced CSS3 like interactivity and animations from clients like the iPhone email client that does. <\/p>\n<p>Thankfully, uber email developer <a href=\"https:\/\/twitter.com\/m_j_robbins\">Mark Robbins<\/a> from <a href=\"https:\/\/www.rebelmail.com\/\">Rebelmail<\/a> came up with a solution that allows you to apply a set of CSS that is only active within Gmail and Inbox.<\/p>\n<h4>Targeting Gmail<\/h4>\n<p><B>Update:<\/B> <I>Gmail made <a href=\"https:\/\/twitter.com\/M_J_Robbins\/status\/910128715144810496\" target=_new>some changes<\/a> on Sept 18, 2017 which affected the techniques used to target the clients. However, <a href=\"https:\/\/twitter.com\/M_J_Robbins\" target=_new>Mark Robbins<\/a> from Rebel quickly came to the rescue. The following has been updated to target Gmail post 9\/18.<\/I> <\/p>\n<p>Here&#8217;s the code to target all Gmail and Inbox versions (Webmail, iOS, Android). <\/p>\n<pre class=\"lang:default mark:1,9,10 decode:true \" >&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;&lt;head&gt;\r\n&lt;style&gt;\r\n    u + .body .gmail{\r\n        display:block !important;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body class=\"body\"&gt;\r\n  &lt;div class=\"gmail\" style=\"display:none;\"&gt;\r\n    THIS IS GMAIL OR INBOX\r\n  &lt;\/div&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>In order to implement this technique your markup must contain<br \/>\n1) A DOCTYPE.<br \/>\n2) A body with a class name (ie. &#8220;body&#8221;)<br \/>\n3) An element with a class name (ie. &#8220;gmail&#8221;)<\/p>\n<p>What happens is Gmail converts the doctype to &lt;u&gt;&lt;\/u&gt; elements and places it adjacent to the body container (transformed into a div with classname body).  Since Gmail is the only client that does this, you are able to target Gmail using the CSS in the code block above.<\/p>\n<p><B>Shortcut<\/B><\/p>\n<p>Cosmin commented below that you can use a shortcut that does not require adding a class to the body of your email. However this technique requires that you NOT use the &lt;u&gt; tag anywhere in your email content.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;&lt;head&gt;\r\n&lt;style&gt;\r\n    u ~ div .gmail{\r\n        display:block !important;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n  &lt;div class=\"gmail\" style=\"display:none;\"&gt;\r\n    THIS IS GMAIL OR INBOX\r\n  &lt;\/div&gt;\r\n&lt;\/body&gt;&lt;\/html&gt;<\/pre>\n<p><BR> <\/p>\n<p><H4>Targeting Gmail on Android Only<\/h4>\n<p>The CSS below allows you to target Gmail on Android (excludes Inbox).<\/p>\n<pre class=\"lang:default decode:true \" >&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;&lt;head&gt;\r\n&lt;style&gt;\r\n    div > u + .body .gmail{\r\n        display:block !important;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body class=\"body\" &gt;\r\n  &lt;div class=\"gmail\" style=\"display:none;\"&gt;\r\n    THIS IS GMAIL ON ANDROID\r\n  &lt;\/div&gt;\r\n&lt;\/body&gt;&lt;\/html&gt;<\/pre>\n<p><BR> <\/p>\n<p><B>Shortcut<\/B><\/p>\n<p>Like the generic version, you can use a shortcut that does not require adding a class name to the body as well.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n    div > u ~ div .gmail{\r\n        display:block !important;\r\n    }\r\n<\/pre>\n<p><BR> <\/p>\n<p>(Originally posted Oct 8, 2016. Updated Sept 19, 2017)<\/p>\n<p><BR><BR><\/p>\n<div style=\"padding:10px; border: 2px solid #99C731;background-color:#FFF8DC;border-radius:5px;\">\n<form action=\"https:\/\/freshinbox1.createsend.com\/t\/i\/s\/adrmi\/\" method=\"post\" id=\"subForm\">\n<span class=\"fisub_header\" style=\"font-weight:bold;\">Subscribe to the #EmailGeeks Newsletter<\/span>\n<p><input id=\"fieldEmail\" name=\"cm-adrmi-adrmi\" type=\"email\" style=\"width:90%\" required placeholder=\"Your Email Address\" \/><\/p>\n<p><button type=\"submit\">Subscribe<\/button><\/p>\n<\/form>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>With the new Gmail update it is now harder to use CSS to distinguish Gmail that doesn&#8217;t support advanced CSS3 like interactivity and animations from clients like the iPhone email client that does.<BR><BR> <\/p>\n<p>Thankfully, uber email developer <a href=\"https:\/\/twitter.com\/m_j_robbins\">Mark Robbins<\/a> from <a href=\"https:\/\/www.rebelmail.com\/\">Rebel<\/a> came up with a solution that allows you to apply a set of CSS that is only active within Gmail and Inbox.<\/p>\n","protected":false},"author":2,"featured_media":3248,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,28],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/3233"}],"collection":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/comments?post=3233"}],"version-history":[{"count":17,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/3233\/revisions"}],"predecessor-version":[{"id":3507,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/3233\/revisions\/3507"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/3248"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=3233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=3233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=3233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}