Rollover or Tap to Reveal Technique in Email
Here’s a way to implement a neat “rollover to reveal” message in email. You can send an email that has a teaser cover message that when the recipient hovers the cursor over the message it reveals a hidden surprise message. Mobile users see the message when the image is tapped.
This technique is similar to the straightforward rollover images in email with one important difference – Instead of showing the initial image as a fallback to non-supported clients, this technique shows the revealed message.
This way recipients using clients that don’t support the rollover technique won’t miss out on the message. They just miss out on the novelty.
Users that see interactive version:
iOS Mail, Android 4.x Mail, Yahoo! Mail, Outlook.com and Gmail.com (requires attribute selector hack).
Users that see the revealed message only:
Desktop Outlook, Gmail mobile apps and Gmail for business.
Try out the Image Carousel for Email Tool.
Difference From Regular Rollover
To support the reveal use-case, we will make some slight changes to the technique. Instead of placing the cover image (closed envelope) as the overlay image and the revealed image as the background image, we switch it.
<table border=1 cellpadding=0 cellspacing=0 background="https://freshinbox.com/examples/rollover-reveal-simple/images/reveal-close-l.jpg"> <tr><td> <a class="reveal" lang="x-reveal" style="display:block;width:500px;height:400px;" href="#"> <img src="https://freshinbox.com/examples/rollover-reveal-simple/images/reveal-open-l.jpg" style="display:block;" height=400 width=500 alt="A surprise!" border=0> </a> </td></tr></table>
The revealed image is placed as the image and the cover image is placed as the background. Then on supported clients, we initially hide the overlay image (the revealed image) showing the cover image. Then when the user hovers over the unit, the hidden overlay image containing the revealed image is shown.
So instead of:
.rollover:hover img{ max-height: 0px; height:0px; }
We reverse it and have the revealed overlay image initially hidden and then displayed when the user hovers over the area:
.reveal img{ max-height: 0px; height:0px; } .reveal:hover img{ max-height: none; height: auto; }
This way if a client does not support interactivity, the revealed image is shown by default. This takes away the “surprise” or novelty, but at least the recipient will see the message.
For regular rollovers such as a product rollover where you want to show the first image as fallback, you would continue to use the original rollover method. Only use this if you need to use the reveal method.
Also you may notice that the image is wrapped with a dead link. This is needed for the hover event to fire on iOS. You could put in a real link, but then Android users who tap on the image will immediately be taken to the link.
Alternatively you could disable interactivity on mobile and just show the revealed message using this media query:
@media screen and (max-device-width: 1024px){ .reveal img{ max-height: none !important; height: auto !important; } }
Source Code
See the Pen RPEbmN by FreshInbox (@freshinbox) on CodePen.
Next Step
I will be updating the Rollover Images for Email Tool to support the reveal use case shortly, but if you’re interested it would be a worthwhile exercise to play around!
Note: An earlier version of this post did not include the support of mobile clients. Jaina’s comment below spurred me to make the change :)
What about mobile/touch screen devices, where there’s no rollover as such?
Hey Jaina, thanks for chiming in! I updated the article to address mobile :)
The techniques you come up with are amazing! Thanks for sharing. Going to try this one on an upcoming birthday message I’m working on.
Is there a way to make the background image fluid responsive?
Unfortunately many clients don’t support background image sizes that are needed to make it fluid responsive. However by using two (non background) images you can make it fluid but will involve a bit more markup to execute.
This is great. Thanks for sharing. I’m still having an issue disabling the reveal for mobile. Is there something I’m missing?
Here is my code:
@media screen and (max-device-width: 1024px){
.reveal img{
max-height: none !important;
height: auto !important;
}
}
@media screen and (max-width:9999px) {
.reveal img{
display: none !important;
max-height: 0px;
height:0px;
}
.reveal:hover img{
display: block !important;
max-height: none;
height: auto;
}
* [lang=x-reveal] img{
max-height: 0px;
height:0px;
}
* [lang=x-reveal]:hover img{
max-height: none;
height: auto;
}
}
I noticed you added a
display: none !important
. That causes it to not be disabled using the code snippet I provided..reveal img{
display: none !important;
max-height: 0px;
height:0px;
}
Hi guys, i’ve add some % in width to make it fully responsive and fix the heights in a rookie mode, the result is this http://codepen.io/gnicky_it/pen/eJKRvO.
What do you think about it?
Hey that’s cool! That example doesn’t work for Gmail and it kinda breaks in Outlook (both images are shown) but with a few tweaks it should work. I created a responsive rollover that I just was about to post that uses a dual image technique except it contains an extra div wrapped around the alternate image to hide it from Outlook. When I get a chance I’ll post a codepen to it.
Hi Justin, thanks for the tip.
I raise adding a quest… what have I to do if I got a table, and not only some images, to hide and show only on hover?
You can replace the image with a div and put any content you want inside it. Then in the style block instead of targeting the img you target the div’s class instead. You probably also need to use Outlook conditional comments so that the contents remain hidden in Outlook as well.
Hey Justin,
Did you get round to posting this? It’s something I’ve been looking into but my solutions are not particularly reliable. I’m interested in seeing what you came up with.
I think it’s a really nice feature for certain emails.
First off – this is a blast to play with. That said, I cannot get this to work in gmail when I send through mailchimp – even when using the exact code in the codepen above. Any ideas on why that is?
Thanks again for this!
Hmm, does it work when you send it to your gmail account from this page? This only works in the Gmail webmail for gmail.com addresses.
Hi there – is there a “click” or “tap” only option? Can I make this trackable?
You have two options, to only make it interactive in a mobile device, you can put the interactive code in a media query.
Otherwise you can use the checkbox method but it will require more work.
http://freshinbox.com/blog/interactive-tabs-for-email/
Here’s an article on how to implement tracking.
http://freshinbox.com/blog/tracking-interactions-in-email-with-google-analytics/
Can you confirm that is not anymore compatible with Gmail (desktop)? It stopped to work since a few days ago :(