Skip to content

EmailEncrypt: hide email addresses from scrapers

How to use the EmailEncrypt React component from Hazeloft Security to keep your email addresses out of the served HTML and away from scrapers.

Last updated:

A mailto: written directly in markup is harvested by bots that download the page and look for addresses with a regular expression. <EmailEncrypt /> keeps the address out of the served HTML.

You can check your own site:

curl -s https://example.com/contact | grep -o '[a-z0-9._+-]*@[a-z0-9.-]*'

Usage

import { EmailEncrypt } from "@hazeloft/security/react";

<EmailEncrypt mail="hello@example.com" className="underline" fallbackHref="/contact" />

How it works

The address does not appear in the served HTML. An obfuscated token and a mask of the same length appear instead. After hydration, the token is decoded and the visitor sees a normal link.

A crawler that runs JavaScript, such as Googlebot, also sees a normal link.

Render the component on the server

The protection is real only if <EmailEncrypt /> renders as a Server Component. As a client component, the address would travel in the hydration payload or in the JavaScript bundle, where scrapers can read it.

react is an optional peer dependency: the core package does not depend on React.

Options

Prop What it does
mail The real address.
className CSS classes for the link.
subject A subject prefilled in the mail client.
fallbackHref Where the link goes for visitors without JavaScript.
revealOn "mount" (the default) or "interaction".

With revealOn="interaction", the href attribute is written only on hover, focus or click:

<EmailEncrypt mail="hello@example.com" revealOn="interaction" fallbackHref="/contact" />

How much it protects

A client that runs JavaScript can obtain the address, just as a person’s browser does; otherwise the link would not work. The component stops those that download the page and look for addresses without running anything.

Without React

The base functions are exported from the main package:

import { obfuscateEmail, deobfuscateEmail, maskEmail } from "@hazeloft/security";

const token = obfuscateEmail("hello@example.com");
deobfuscateEmail(token); // "hello@example.com"

All documentationSecurity product page

This site uses measurement and advertising technologies. You can accept or decline them.

How we handle your data: Privacy policy · Cookie policy