Email obfuscation
This guide helps you to obfuscate email addresses with a simple, effective CSS technique.
Background
The article Email Obfuscation: What Works in 2024 by Spencer Mortensen discusses various techniques to hide email addresses from spam bots while keeping them accessible to users. It evaluates methods like plain text, HTML entities, CSS display properties, JavaScript techniques, and others, testing their effectiveness in blocking spam.
Some methods, such as CSS display: none
and certain JavaScript techniques, are found to be highly effective, while others like HTML comments and symbol substitution offer little protection.
Setup
-
Add a default (fallback) email address to
config/_default/params.toml
: -
Add the following CSS to
assets/scss/common/_custom.scss
: -
Create shortcode file
layouts/shortcodes/email.html
with the following content:The shortcode gets the email address you provided — using the default email address if you didn’t specify one. Next, it splits the email address in parts —
userName
,domainName
, andtopLevelDomain
— and renders the HTML.
Usage
Now, you can use the shortcode in Markdown — using defaultEmail
:
Rendering:
Or, by specifying an email address:
Rendering:
Learn