{"id":235872,"date":"2015-12-22T07:26:04","date_gmt":"2015-12-22T14:26:04","guid":{"rendered":"http:\/\/css-tricks.com\/?p=235872"},"modified":"2022-12-07T11:29:49","modified_gmt":"2022-12-07T19:29:49","slug":"a-guide-on-svg-support-in-email","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/a-guide-on-svg-support-in-email\/","title":{"rendered":"A Guide for SVG Support in Email"},"content":{"rendered":"\n
We\u2019ve talked about SVG quite a bit<\/a> here on CSS-Tricks, but one area we haven\u2019t quite touched on is email. Now that browser support for SVG is all in the green<\/a>, it would be easy to assume that we can start using SVG everywhere. However, if you\u2019ve worked with email before, you may know that it often follows way behind the web as far as feature support. You know, kinda the way California looks at North Dakota with trends: just a few years behind. :)<\/p>\n\n\n\n This article takes a deep dive into four different ways SVG can be used, and compares support for those methods across several of the most popular email applications. Let\u2019s see where we get the most support.<\/p>\n\n\n\n\n\n\n\n Using SVG as a straight-up Here\u2019s the support for this technique:<\/p>\n\n\n\n Total support:<\/strong> 60%<\/p>\n\n\n In this test, we\u2019re plucking the code for the SVG file right out of Illustrator and plopping it directly into the email\u2019s HTML:<\/p>\n\n\n\n The support is a lot less than I expected:<\/p>\n\n\n\n Total support:<\/strong> 25% (counting Android as partial support)<\/p>\n\n\n\n You might have noticed that I assigned class names for each path. If you were hoping the CSS properties for SVG are also supported for those email clients that recognize inline SVG, well, you\u2019re in luck. They are, across the board.<\/p>\n\n\n We can use SVG as a background image in CSS:<\/p>\n\n\n\n Total support:<\/strong> 40%<\/p>\n\n\n\n Note that some email applications are known to strip CSS from the document Also, CSS backgrounds are a bit unpredictable if we’re dealing with a responsive design. Keeping the width and height proportional to each other would be tricky, and probably more hassle than it’s worth.<\/p>\n\n\n Embedding SVG as an \n
\n\n\nSVG as Image Tag<\/h3>\n\n\n
<\/code> tag is like placing any other image file onto a screen, except we\u2019re referencing an SVG file instead something like a JPG or PNG:<\/p>\n\n\n\n
<img src=\"my-image.svg\" alt=\"A pair of flat black dice, one on 5 and one on 3\"><\/code><\/pre>\n\n\n\n
AOL Web<\/th> Outlook 2013<\/th> Outlook
.com<\/th>Yahoo!<\/th> Mail (OSX)<\/th> Mail (iOS)<\/th> Gmail<\/th> Gmail (iOS)<\/th> Gmail (Android)<\/th> Android<\/th><\/tr><\/thead> Yes<\/td> No<\/td> Yes<\/td> Yes<\/td> Yes<\/td> Yes<\/td> No<\/td> No<\/td> Yes<\/td> No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n SVG as Inline HTML<\/h3>\n\n\n
<svg version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" xmlns:xlink=\"http:\/\/www.w3.org\/1999\/xlink\" viewBox=\"-227 241 225.3 224.1\" style=\"enable-background:new -227 241 225.3 224.1;\" xml:space=\"preserve\">\n <path class=\"dice-1\" d=\"M-132,241h-72.3c-12.4,0-22.6,10.2-22.6,22.6V336c0,12.4,10.2,22.6,22.6,22.6h72.3c12.4,0,22.6-10.2,22.6-22.6\n v-72.3C-109.4,251.2-119.6,241-132,241z M-195.3,340.5c-7.5,0-13.6-6.1-13.6-13.6c0-7.5,6.1-13.6,13.6-13.6\n c7.5,0,13.6,6.1,13.6,13.6C-181.8,334.4-187.9,340.5-195.3,340.5z M-195.3,286.2c-7.5,0-13.6-6.1-13.6-13.6\n c0-7.5,6.1-13.6,13.6-13.6c7.5,0,13.6,6.1,13.6,13.6C-181.8,280.1-187.9,286.2-195.3,286.2z M-168.2,313.3\n c-7.5,0-13.6-6.1-13.6-13.6c0-7.5,6.1-13.6,13.6-13.6s13.6,6.1,13.6,13.6C-154.7,307.3-160.7,313.3-168.2,313.3z M-141.1,340.5\n c-7.5,0-13.6-6.1-13.6-13.6c0-7.5,6.1-13.6,13.6-13.6c7.5,0,13.6,6.1,13.6,13.6C-127.5,334.4-133.6,340.5-141.1,340.5z\n M-141.1,286.2c-7.5,0-13.6-6.1-13.6-13.6c0-7.5,6.1-13.6,13.6-13.6c7.5,0,13.6,6.1,13.6,13.6C-127.5,280.1-133.6,286.2-141.1,286.2\n z\"\/>\n <path class=\"dice-2\" d=\"M-24.3,347.5h-72.3c-12.4,0-22.6,10.2-22.6,22.6v72.3c0,12.4,10.2,22.6,22.6,22.6h72.3\n c12.4,0,22.6-10.2,22.6-22.6v-72.3C-1.7,357.7-11.9,347.5-24.3,347.5z M-87.6,447c-7.5,0-13.6-6.1-13.6-13.6\n c0-7.5,6.1-13.6,13.6-13.6c7.5,0,13.6,6.1,13.6,13.6C-74.1,441-80.1,447-87.6,447z M-60.5,419.9c-7.5,0-13.6-6.1-13.6-13.6\n c0-7.5,6.1-13.6,13.6-13.6s13.6,6.1,13.6,13.6C-46.9,413.8-53,419.9-60.5,419.9z M-33.4,392.8c-7.5,0-13.6-6.1-13.6-13.6\n s6.1-13.6,13.6-13.6s13.6,6.1,13.6,13.6S-25.9,392.8-33.4,392.8z\"\/>\n<\/svg><\/code><\/pre>\n\n\n\n
AOL Web<\/th> Outlook 2013<\/th> Outlook.com<\/th> Yahoo!<\/th> Mail (OSX)<\/th> Mail (iOS)<\/th> Gmail<\/th> Gmail (iOS)<\/th> Gmail (Android)<\/th> Android<\/th><\/tr><\/thead> No<\/td> No<\/td> No<\/td> No<\/td> Yes<\/td> Yes<\/td> No<\/td> No<\/td> No<\/td> Yes*<\/sup><\/td><\/tr><\/tbody><\/table> fill<\/code><\/h4>\n\n\n
Mail (OSX)<\/th> Mail (iOS)<\/th> Android<\/th><\/tr><\/thead> Yes<\/td> Yes<\/td> Yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n stroke<\/code><\/h4>\n\n\n
Mail (OSX)<\/th> Mail (iOS)<\/th> Android<\/th><\/tr><\/thead> Yes<\/td> Yes<\/td> Yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n SVG as CSS background Image<\/h3>\n\n\n
.my-element {\n background-image: url(\"my-image.svg\");\n background-repeat: no-repeat;\n}<\/code><\/pre>\n\n\n\n
AOL Web<\/th> Outlook 2013<\/th> Outlook.com<\/th> Yahoo!<\/th> Mail (OSX)<\/th> Mail (iOS)<\/th> Gmail<\/th> Gmail (iOS)<\/th> Gmail (Android)<\/th> Android<\/th><\/tr><\/thead> Yes<\/td> No<\/td> No<\/td> Yes<\/td> Yes<\/td> Yes<\/td> No<\/td> No<\/td> No<\/td> No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n <\/code>. In these cases, it is a best practice to inline our styles in addition to including them in the
<\/code>.<\/p>\n\n\n\n
SVG as Object Embed<\/h3>\n\n\n
<object><\/code> is a lot like embedding a media file, like audio or video. The benefit\u2014aside from retaining some styling control with CSS\u2014is that a fallback image can be set where SVG is not supported: