{"id":71480,"date":"2022-05-10T02:54:00","date_gmt":"2022-05-09T16:54:00","guid":{"rendered":"https:\/\/elements.blog-cms.envato.net\/?p=43451"},"modified":"2026-04-25T04:33:30","modified_gmt":"2026-04-24T18:33:30","slug":"protect-html-email-links","status":"publish","type":"post","link":"https:\/\/elements.envato.com\/learn\/protect-html-email-links","title":{"rendered":"2 Ways to Protect Your HTML Email Links (and Prevent Spam)"},"content":{"rendered":"\n<p>In this tutorial, I\u2019ll describe two straightforward techniques for protecting HTML email links from being scraped by spammers. Although these techniques cannot guarantee full success, they\u2019ll give you an extra layer of protection.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Email Templates on Envato Elements<\/h2>\n\n\n\n<p>Before we dive in, don\u2019t forget that you can download unlimited <a rel=\"noopener\" href=\"https:\/\/elements.envato.com\/web-templates\/email-templates\" target=\"_blank\">email templates with your Envato Elements subscription<\/a>, to use with Mailchimp, Campaign Monitor, and many other Email Service Providers. Envato Elements also gives you access to thousands of other creative assets, like stock photos, graphics, video templates, audio, Photoshop actions, you name it!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/elements.envato.com\/web-templates\/email-templates\"><img decoding=\"async\" width=\"850\" height=\"406\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/email-templates.jpg\" alt=\"email templates on envato elements\" class=\"wp-image-86574\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/email-templates.jpg 850w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/email-templates-300x143.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/email-templates-768x367.jpg 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s the Problem With HTML Email Links?<\/h2>\n\n\n\n<p>HTML email links do exactly what you\u2019d want them to do: when users click on them, they open the default email application and begin a new email with the contact email address\u2014and perhaps other details\u2014already filled in. They\u2019re really convenient! However, the email address (either in text form in the link or in the <code>href<\/code> attribute) is readable by bots and <a href=\"https:\/\/blog.apify.com\/best-web-scraping-tools\/\" data-type=\"URL\" data-id=\"https:\/\/blog.apify.com\/best-web-scraping-tools\/\" target=\"_blank\" rel=\"noreferrer noopener\">scraping tools<\/a>\u2014even those operating through a <a href=\"https:\/\/decodo.com\/blog\/what-is-a-proxy-server\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/decodo.com\/blog\/what-is-a-proxy-server\" rel=\"noreferrer noopener\">proxy server<\/a>\u2014 often leading to that email address finding its way onto spam mailing lists of all kinds.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"850\" height=\"618\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/spamming.jpg\" alt=\"spamming\" class=\"wp-image-86575\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/spamming.jpg 850w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/spamming-300x218.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/spamming-768x558.jpg 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/figure>\n\n\n\n<p>The solutions we\u2019re looking at aim to <em>hide<\/em> the email addresses from the DOM, so web crawlers cannot find them and put them into spamming lists.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A Specific Email Link Example<\/h3>\n\n\n\n<p>Let\u2019s describe the problem in a bit more detail and then move on to the solutions.<\/p>\n\n\n\n<p>The links won\u2019t trigger in the embedded demos, so be sure to view them in the full page view (debug mode).<\/p>\n\n\n\n<p>Consider the following example (<a rel=\"noopener\" href=\"https:\/\/cdpn.io\/pen\/debug\/NWyNNNW\" target=\"_blank\">debug mode<\/a>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codepen.io\/tutsplus\/pen\/NWyNNNW\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"601\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen1-1024x601.jpg\" alt=\"codepen 1\" class=\"wp-image-86576\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen1-1024x601.jpg 1024w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen1-300x176.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen1-768x451.jpg 768w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen1.jpg 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">How to Link Email in HTML<\/h4>\n\n\n\n<p>Here we\u2019ve defined three regular links that, when clicked, instead of redirecting to a URL will open the user\u2019s default email client with the recipient\u2019s address and email subject prefilled. We do this by appending the <code>mailto:<\/code> HTML scheme at the beginning of the <code>href<\/code> attribute. As well as the <code>subject<\/code> parameter, we can pass some things like the <code>cc<\/code> and <code>body<\/code>.<\/p>\n\n\n\n<p>Notice also that the subject value is URL-encoded (the space is replaced by the <code>%20<\/code>). For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;a href=\"mailto:hello@forecastr.com?subject=General%20Questions\"&gt;General Questions&lt;\/a&gt;<\/code><\/pre>\n\n\n\n<p>Email addresses, when displayed like this, form a regular part of the DOM. And that is a problem. A bot can easily find them and target them with bulk advertisements and other unwanted stuff.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HTML Email Link Solution #1: Encoding<\/h2>\n\n\n\n<p>In this first technique, we\u2019ll represent all the characters of our email addresses with encoded entities. For example, the \u201ch\u201d character will be represented by the entity <code>h<\/code>. Different online tools can provide this functionality, like the <a class=\"editor-rtfLink\" rel=\"noopener\" href=\"https:\/\/www.wbwip.com\/wbw\/emailencoder.html\" target=\"_blank\">one<\/a> I used for our example.<\/p>\n\n\n\n<p>Here\u2019s the related demo (<a rel=\"noopener\" href=\"https:\/\/cdpn.io\/pen\/debug\/GRQZZGV\" target=\"_blank\">debug mode<\/a>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codepen.io\/tutsplus\/pen\/GRQZZGV\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"600\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen2-1024x600.jpg\" alt=\"codepen 2\" class=\"wp-image-86577\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen2-1024x600.jpg 1024w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen2-300x176.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen2-768x450.jpg 768w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen2.jpg 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Here\u2019s what that first link looks like now:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;a href=\"mailto:hello@forecastr.com?subject=General%20Questions\"&gt;General Questions&lt;\/a&gt;<\/code><\/pre>\n\n\n\n<p>If you want to replace the text links with the actual email addresses so people can see and select them, all you have to do is replace them with the encoded entities like the demo below (<a rel=\"noopener\" href=\"https:\/\/cdpn.io\/pen\/debug\/dydMMqa\" target=\"_blank\">debug mode<\/a>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codepen.io\/tutsplus\/pen\/dydMMqa\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"601\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen3-1024x601.jpg\" alt=\"codepen 3\" class=\"wp-image-86578\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen3-1024x601.jpg 1024w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen3-300x176.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen3-768x451.jpg 768w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen3.jpg 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This is a simple enough approach and will offer reasonable protection; it will prevent the majority of bots from harvesting the email addresses.<\/p>\n\n\n\n<p>For WordPress websites, you can automate this process with the <a href=\"https:\/\/wordpress.org\/plugins\/email-address-encoder\/\" target=\"_blank\" rel=\"noreferrer noopener\">email address encoder<\/a> plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HTML Email Link Solution #2: JavaScript<\/h2>\n\n\n\n<p>For this second technique, we\u2019re going to use a tiny bit of JavaScript. The <code>href<\/code> attribute value of our links will be empty by default. Additionally, each link will have <code>data-part1<\/code>, <code>data-part2<\/code>, and <code>data-part3<\/code> attributes. The value of the first attribute will correspond to the user, the value of the second one to the domain name, and the value of the third one to the domain extension.<\/p>\n\n\n\n<p>When the page loads, we\u2019ll loop through all page links and update their <code>href<\/code> attribute values by combining the aforementioned attributes.<\/p>\n\n\n\n<p>Here\u2019s the related demo (<a rel=\"noopener\" href=\"https:\/\/cdpn.io\/pen\/debug\/poaybzW\" target=\"_blank\">debug mode<\/a>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codepen.io\/tutsplus\/pen\/poaybzW\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"605\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen4-1024x605.jpg\" alt=\"codepen 4\" class=\"wp-image-86579\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen4-1024x605.jpg 1024w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen4-300x177.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen4-768x454.jpg 768w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen4.jpg 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Here\u2019s what the first link looks like in this example\u2014it\u2019s very unlikely bots will be able to interpret our data in this form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;a href=\"\" data-part1=\"hello\" data-part2=\"forecastr\" data-part3=\"com\"&gt;General Questions&lt;\/a&gt;<\/code><\/pre>\n\n\n\n<p>Again, if you need people to be able to read the email addresses, consider the following JavaScript solution (<a rel=\"noopener\" href=\"https:\/\/cdpn.io\/pen\/debug\/eYVZzpr\" target=\"_blank\">debug mode<\/a>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/codepen.io\/tutsplus\/pen\/eYVZzpr\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"602\" src=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen5-1024x602.jpg\" alt=\"\" class=\"wp-image-86580\" srcset=\"https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen5-1024x602.jpg 1024w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen5-300x176.jpg 300w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen5-768x451.jpg 768w, https:\/\/elements.envato.com\/learn\/wp-content\/uploads\/2024\/02\/codepen5.jpg 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This technique will only work if JavaScript is enabled.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this tutorial, we examined two quick methods to protect our HTML email links and fight against email spamming. As I said at the beginning, none of them can guarantee full spam protection, and each one does have downsides. Of course, each bot collects data differently, and thus their efficiency varies. What we can at least do is try different methods for making their job more difficult in stealing our email addresses.<\/p>\n\n\n\n<p>There are also other methods that I didn\u2019t cover here, possibly more effective, so be sure to let us know if you\u2019re aware of any of them.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For example, one such rough solution uses pseudo-elements to create the email addresses and display them on the screen. However, its main limitation stems from the fact that pseudo-elements aren\u2019t considered real elements, so people can&#8217;t select them and interact with them.<\/li>\n\n\n\n<li>Another common approach takes advantage of <a rel=\"noopener\" href=\"https:\/\/support.cloudflare.com\/hc\/en-us\/articles\/200170016-What-is-Email-Address-Obfuscation-\" target=\"_blank\">Cloudflare\u2019s Email Address Obfuscation<\/a> feature.<\/li>\n\n\n\n<li>Lastly, another technique might be to reverse how the email address links <em>appear<\/em> by using either CSS\u2019s <code><a rel=\"noopener\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/unicode-bidi\" target=\"_blank\">unicode-bidi<\/a><\/code> property or JavaScript methods like the <a rel=\"noopener\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/split\" target=\"_blank\"><code>split()<\/code><\/a> one. The disadvantage of this technique, though, is that if people select the email address and paste it into their mailing program, the email address characters will be displayed in reverse order. A quick and dirty solution to this is to disable text selection for the target links.<\/li>\n<\/ul>\n\n\n\n<p>As always, thanks a lot for reading!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HTML Template Collections on Envato Tuts+<\/h2>\n\n\n\n<p>Kick off your next HTML website quickly and easily with one of the thousands of <a href=\"https:\/\/elements.envato.com\/web-templates\">HTML templates<\/a> we have at Envato Elements. Check out these collections!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/articles\/best-website-templates-html--cms-38299\" target=\"_blank\" rel=\"noopener\">20 Best Website Templates (HTML) for 2024<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/tutorials\/how-to-customize-an-html-template--cms-25886\" target=\"_blank\" rel=\"noopener\">How to Customize an HTML Template<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/articles\/best-portfolio-html-templates--cms-37445\" target=\"_blank\" rel=\"noopener\">14 Best Portfolio HTML Templates to Show Off Your Work<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/articles\/best-university-website-templates--cms-37137\" target=\"_blank\" rel=\"noopener\">13 Best University Website Templates (HTML)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/articles\/best-dj-website-templates--cms-38341\" target=\"_blank\" rel=\"noopener\">10 Best HTML DJ Website Templates<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/articles\/html-gaming-website-templates--cms-35667\" target=\"_blank\" rel=\"noopener\">25+ Awesome &amp; Fun Gaming Website Templates HTML5 (Free &amp; Premium)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/webdesign.tutsplus.com\/articles\/best-new-html-templates-for-your-blog--cms-37443\" target=\"_blank\" rel=\"noopener\">17+ Best New HTML Templates for Your Blog<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to protect your HTML email links from spammers.<\/p>\n","protected":false},"author":192,"featured_media":86573,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[207],"tags":[],"class_list":["post-71480","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-design"],"acf":[],"_links":{"self":[{"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/posts\/71480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/users\/192"}],"replies":[{"embeddable":true,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/comments?post=71480"}],"version-history":[{"count":1,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/posts\/71480\/revisions"}],"predecessor-version":[{"id":99639,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/posts\/71480\/revisions\/99639"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/media\/86573"}],"wp:attachment":[{"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/media?parent=71480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/categories?post=71480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elements.envato.com\/learn\/wp-json\/wp\/v2\/tags?post=71480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}