How To Code HTML5 Video Background In Email
By Kevin Mandeville, Content Designer at Litmus, @kevingotbounce
Recently, our company sent the launch email for The Email Design Conference. We knew we couldn’t promote an Email Design Conference with just any email, which is why we aimed for a forward-thinking and uniquely impressive one.
Naturally, we wanted it to be so amazing that people couldn’t help but attend the conference to learn about the tricks we used.
So, what did we decide to do? We used an HTML5 video background. That’s right: video background in an email.
In addition, you can view the Litmus test results of the final email sent to subscribers (note some screenshots may be “wonky” due the video animation). The video background worked in the following clients:
- Apple Mail
- Outlook 2011 (Mac)
As you can see, the HTML5 video degrades gracefully across all clients with the fallback image.
We expected the email to get some attention, but the response we received blew our socks off. We’re proud to report that it prompted hundreds of tweets — generating comments, questions, and praise.
With such an overwhelming response, we fast-tracked this blog post breaking down the methodology and process behind the email. Here’s a step-by-step guide to the implementation of this responsive email.
Designing For Desktop
First off, we created a full-width table as a container for the top section of the email:
Within that table, we created a table cell with a “fallback” background image that acted as a static image for when the video was not loaded:
The fallback background image looked like this:
Creating a fallback background image was necessary for two reasons:
- The majority of email clients do not support video backgrounds.
- Some subscribers may have trouble downloading the video background due to large file size.
It was also important to include a background color on both the <table> and <td> to ensure there was a fallback when images were disabled. This step was crucial for subscribers using Outlook, AOL Mail, and other email clients that block images by default, and was especially important for our email since the design uses white text in the video section—we wanted to avoid white text on a white background.
Next, we used a wrapper <div> for the video as the first element in the <td>:
Since video backgrounds are only supported in Webkit-based clients (Apple Mail and Outlook 2011 for Mac), a Webkit-only media query was used to apply CSS to the <div> only when a Webkit client was detected:
The CSS applied to the “video-wrap” <div> above specifies a defined height, a relative position, eliminates any overflow of content inside, and eliminates any padding or margins.
Next, we put the <video> inside the “video-wrap” <div>:
We used an .mp4 version of the video since video background is only supported in Webkit-based email clients. We could have included an .ogg file for subscribers opening the web version in Firefox, but didn’t feel that the extra payload was necessary for our audience.
It’s also important to note that we hid the <video> by default using the display: none; property. Since the <video> only works in Webkit-supported email clients, we used a Webkit-targeted media query to overwrite the inline style to display the video for those clients. Here is the CSS for the <video>:
Once again, we only targeted Webkit with this bit of CSS. We specified a minimum height and width of 100% to scale the video to the entire width of the “video-wrapper” <div>.
Since we previously defined the “video-wrapper” <div> to hide any content that overflows, the video wasn’t displayed beyond the specified dimensions of the “video-wrapper” <div>. The video was also given an absolute position (with 0px from the top and left of the page), a z-index value, and a new display value to show the video in Webkit.
Finally, we used an overlay <div> for the content that would be displayed over the video, placing it directly after the <video> tag. Here is the CSS for the “overlay” <div>:
A min-height of 100% was used to fill the entire height of the content area, along with a relative position and a higher z-index, so that the overlaid content would display on top of the video.
Then, we placed the content that we wanted to display over the video inside the “overlay” <div>. The rest of the content followed a standard, table-based structure so that it would render properly in all email clients.
Designing For Mobile
Unfortunately, no major mobile email clients support the use of HTML5 video backgrounds. Most of our own mobile audience uses iOS, which displayed an unwanted play button when video was present.
We needed a way to disable the video from rendering on iOS devices, so we used targeted media queries specific to the device dimensions and pixel ratios of iOS devices to disable the video and ensure that button wouldn’t be rendered:
Using these targeted media queries, we prevented the video from displaying on these devices by setting the display property to none. As an extra measure, a lower z-index ensured that the fallback background image in our <td> was displayed.
However, we still wanted to support the video background on mobile Webkit for viewing the web version or just to showcase the responsiveness on desktop, so the following CSS was applied:
The mobile CSS changed the height of the “video-wrap” <div> to accommodate for smaller image and font sizes and changed the positioning of the <video> to create a better alignment since its true dimensions were not changed.
Positive Feedback Galore!
Video backgrounds aren’t something you see often in emails. It took a lot of thought to implement it correctly, but it paid off — people loved it:
— Emmet Fërdle (@elmitocarboni) April 17, 2014
— Bruce Kaldor (@BruceKaldor) April 17, 2014
— Five & Done Creative (@FiveDone) April 17, 2014
Just received the most mind-blowing marketing email from @litmusapp… Embedded video in an email. How is this even happening!?
— Jono Kane (@nokapixel) April 17, 2014
— Frank (@FrankJuval) April 17, 2014
The awesome @litmusapp email we just received for their Email Design Conference sparked a mini Email Design Conference in the office!
— Judah Stevenson (@judahstevenson) April 17, 2014
If ever there was a baller status for html email design, @litmusapp just took that crown. The Email Design Conference email was awesome
— Gregg Henry (@GreggHenry) April 17, 2014
@litmusapp, just got your Con Save The Date email and WOW. Just WOW.
— Laura Earley (@lauraearley) April 17, 2014
— Andrew King (@akingkiwi) April 17, 2014
— Alessandra Souers (@asouers) April 17, 2014
— Pete Biolsi (@pbiolsi) April 17, 2014
— Graden Hudson (@gradenh) April 18, 2014
I can’t promise you’ll receive the same reaction if you deploy this technique, but it’s worth a try!
Editor’s note: This article has been corrected, as the original contained an error in the coding. We regret the error.
Some opinions expressed in this article may be those of a guest author and not necessarily Marketing Land. Staff authors are listed here.
(Some images used under license from Shutterstock.com.)
Step up your email marketing game with our weekly newsletter.