{"id":2233,"date":"2015-11-05T15:36:48","date_gmt":"2015-11-05T15:36:48","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=2233"},"modified":"2015-11-09T19:20:24","modified_gmt":"2015-11-09T19:20:24","slug":"css-animations-in-email-and-vendor-prefixes","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/css-animations-in-email-and-vendor-prefixes\/","title":{"rendered":"CSS Animations in Email and Vendor Prefixes"},"content":{"rendered":"<p><center><\/p>\n<div class=\"animcontainer\">\n<div class=\"mymove\"><\/div>\n<\/div>\n<p><\/center><\/p>\n<p>Although CSS animations are only supported by modern email clients, used strategically CSS animations can bring a level of flair and sophistication to your email. <\/p>\n<p>There are many excellent <a href=\"http:\/\/webdesign.tutsplus.com\/tutorials\/a-beginners-introduction-to-css-animation--cms-21068\">tutorials on CSS animations<\/a> on the Web so we&#8217;ll skip to the email specific parts.<\/p>\n<p>From the bottom of this <a href=\"https:\/\/freshinbox.com\/resources\/css.php\">kinetic email support chart<\/a>, you can see only the Webkit based email clients with the addition of Windows 8.1 support animations.<BR><BR><\/p>\n<h4>CSS Animation Support in Email.<\/h4>\n<p>Animations allow you to transition styles of an element from one state to another over a period of time &#8211; say moving an element from one point to another, rotating the element or making it appear and disappear gradually.<\/p>\n<p>The basic components of CSS animation are the animation selector and @keyframes. For example with the code below, after a delay of 2 seconds the &#8220;mybox&#8221; element will hide and display over a period of 5 seconds repeatedly:<\/p>\n<pre class=\"lang:default decode:true \" >.mybox{ animation: opacityanim 5s linear 2s infinite alternate; }\r\n\r\n@keyframes opacityanim {\r\n 0% { opacity: 1; }\r\n  100% { opacity: 0;}\r\n}\r\n<\/pre>\n<div class=\"mybox\"><\/div>\n<p>Since animations were added to browsers when the CSS3 spec for animations was still not official  some browsers require adding vendor prefixes to the declarations just in case the final spec is different.<\/p>\n<p>In general, there are four prefixes <code>-webkit<\/code> for webkit based browsers (Safari, Chrome, iOS &#038; Android), <code>-ms<\/code> for Internet Explorer, <code>-moz<\/code> for Firefox and <code>-o<\/code> for Opera.<\/p>\n<p>The code with a vendor prefix for webkit would look like this:<\/p>\n<pre class=\"lang:default decode:true \" >.mybox{ -webkit-animation: opacityanim 5s linear 2s infinite alternate; }\r\n\r\n@-webkit-keyframes opacityanim {\r\n 0% { opacity: 1; }\r\n  100% { opacity: 0;}\r\n}\r\n<\/pre>\n<p>In reality though all modern browsers except Safari support vendor prefixes and the regular non-prefixed selectors for animation. In the land of email however, most Webkit based email clients only support animation selectors with the <code>-webkit-<\/code> vendor prefix.<\/p>\n<p>Here&#8217;s the email client matrix of selector declaration type by email clients that support CSS Animations<\/p>\n<p><b>Email Clients that support CSS Animation<\/b><\/p>\n<table style=\"border:1px solid #555555;\">\n<tr>\n<td><b>Email client<\/b><\/td>\n<td><b>Animation selector<\/b><\/td>\n<\/tr>\n<tr>\n<td>iOS<\/td>\n<td>-webkit, regular<\/td>\n<\/tr>\n<tr>\n<td>Apple Mail<\/td>\n<td>-webkit<\/td>\n<\/tr>\n<tr>\n<td>Android 4.4<\/td>\n<td>-webkit<\/td>\n<\/tr>\n<tr>\n<td>Windows 8.1<\/td>\n<td><b>-webkit<\/b>, -ms, regular<\/td>\n<\/tr>\n<\/table>\n<p>As you can see the from the table above, the only selector we need to be concerned about when working on CSS animations in email is the one with the <code>-webkit<\/code> vendor prefix. Surprisingly the Windows 8.1 client responds to CSS animation and transform selectors with the <code>-webkit<\/code> vendor prefix!<BR><BR><\/p>\n<h4>Using Media Queries to Limit Animation Related CSS<\/h4>\n<p>Technically you don&#8217;t need to add any code to limit your animations to only those clients that support it. That&#8217;s the beauty of progressive enhancement. The clients that support animations would just perform them and those that don&#8217;t will ignore the declarations.<\/p>\n<p>However if you want to style certain elements just for clients that support animation then putting all the animation related styles into this media query would do the trick. This would mean that your animations will no longer work in Windows 8.1, but who uses that client anyways, right? :)<\/p>\n<pre class=\"lang:default decode:true \" >@media screen and (-webkit-min-device-pixel-ratio: 0) {\r\n  ... animation related styles ...\r\n}\r\n<\/pre>\n<p><BR><BR><\/p>\n<h4>A Note About Gmail<\/h4>\n<p>For those of you who are taking advantage of Gmail&#8217;s <a href=\"https:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\/\">limited &lt;style&gt; support<\/a>, make sure to place the Gmail related CSS in a separate &lt;style&gt; block at the top as the animation related declarations may cause the style block to get stripped by Gmail.<BR><BR><BR><\/p>\n<h4>Examples<\/h4>\n<p>Here&#8217;s a post on <a href=\"https:\/\/freshinbox.com\/blog\/css-animation-entrance-effects-in-email\/\">CSS entrance effects in email.<\/a><BR><BR><\/p>\n<p>If you come across some really cool examples of emails using animations, feel free to post a link to it in the comments! <\/p>\n<p><BR><BR><BR><br \/>\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><\/p>\n<style>\n.mybox{ \n width: 100px;height:80px;background-color:#404040; \n margin: 50px;auto;\n animation: opacityanim 5s linear 2s infinite alternate; \n -webkit-animation: opacityanim 5s linear 2s infinite alternate; \n}\n@keyframes opacityanim {\n 0% { opacity: 1; }\n  100% { opacity: 0;}\n}\n@-webkit-keyframes opacityanim {\n 0% { opacity: 1; }\n  100% { opacity: 0;}\n}\n.animcontainer{\n  position:relative;\n  width:150px; height:150px;\n}\n.mymove{\n  top:25px;\n  background-color:#118fca;\n  position:absolute;\n  width:100px; height:100px;\n  border-radius: 100px;\n animation: moveanim 1.5s linear infinite alternate; \n -webkit-animation: moveanim 1.5s linear infinite alternate;\n}\n@keyframes moveanim {\n 0% { left:0px; }\n  100% { left:50px;}\n}\n@-webkit-keyframes moveanim {\n 0% { left:0px; }\n  100% { left:50px;}\n}\n<\/style>\n","protected":false},"excerpt":{"rendered":"<p>Although CSS animations are only supported by modern email clients, used strategically CSS animations can bring a level of flair and sophistication to your email. <\/p>\n","protected":false},"author":2,"featured_media":2258,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,24,25,47],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2233"}],"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=2233"}],"version-history":[{"count":30,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2233\/revisions"}],"predecessor-version":[{"id":2320,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/2233\/revisions\/2320"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/2258"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=2233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=2233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=2233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}