How To Hide Checkbox And Radio Inputs In Email
Update April 2016: Outlook.com introduced a bug that modifies styles of elements next to checkboxes. Check out this article to learn more.
Hidden checkbox and radio inputs are becoming a staple way to introduce interactivity in email. Here’s a simple way to hide these elements in all email clients.
Try out the Image Carousel for Email Builder.
Techniques that don’t work
Hiding techniques vary over the different email clients so its tempting to add other fallback hiding tricks when hiding elements. Unfortunately, the typical methods to hide divs and tables don’t work on form elements and may result in odd spacing artifacts when display: none
is not supported.
Here’s how a checkbox looks like when we style a checkbox with height: 0px; overflow: hidden
(before & after):
As you can see, even with overflow: hidden
, the checkbox is still visible and rendered over the next element.
This technique works
The solution that works is a simple one. Unlike the other hiding techniques, this requires adding a style into the <style> block but it is relatively straightforward:
<style> .hide-input{ display: none; } </style> <!--[if !mso]><!-- --> <input type="checkbox" class="hide-input" style="display: none !important"> <!--<![endif]-->
The technique uses three hiding tricks:
- Gmail only supports display: none when accompanied by !important.
- Yahoo! Mail does not support display: none inline but allows display: none in the embedded style.
- The trusty ol Outlook conditional comment to hide the element in Outlook.
As you can see this works without the usual overflow, height, font-size, line-height, visibility baggage.
Good stuff, Justin. Love these little bitesized bits of info!
Great, very nifty diagram and explanation. thanks.
fantastic, I’ve been looking at how to get this to work for ages, thanks
Thank you for this article. It inspired me to make this GIF. Because this is really looking like a game of wack-a-mole, isn’t it ?
Everything I look up always leads back to your blog posts. Thanks a lot for this tip. It helped fixed the GMAIL checkbox issue