Canddi

HTML: E-mail Address Linking & Spam Protection

An HTML email link uses mailto: to ask the visitor’s device to open a new message. You can also suggest a subject and short body. This guide shows the markup, explains the encoding, and corrects a common misconception: encoding an email address in HTML does not reliably protect it from spam.

Create a basic email link

<a href="mailto:hello@example.com">
  Email hello@example.com
</a>

Replace hello@example.com with an inbox you control. The address here is a documentation example, not a working contact address. Keep useful link text so readers know what will happen, and show the address in plain text so they can copy it if their device has no email app configured.

A mailto link opens a composition window or a handler prompt when supported. It does not send a message automatically, and it does not provide a form inside your website. The result depends on the visitor’s email application and browser settings.

Add a subject and message body

Start the optional fields with ?, then separate fields with &. In HTML source, write that separator as &amp;. Encode spaces and special characters within the field values.

<a
  href="mailto:hello@example.com?subject=Hello&amp;body=Hi%20there."
>
  Start an email enquiry
</a>

This example requests the subject Hello and the body Hi there. The visitor can edit both before sending. Keep prefilled messages short and do not put passwords, private account details or other sensitive information into a public link.

Encoding used in mailto links
You need Use
A space in a value %20
An ampersand inside the subject or body %26
A line break in the body %0D%0A
A separator between fields in HTML source &amp;

The two encoding steps serve different purposes: percent-encoding represents characters inside the URI, while HTML character references make the attribute valid HTML. For the full syntax, see RFC 6068, the mailto URI scheme.

Why character encoding is not spam protection

Obscuring an address is not the same as keeping it private.

HTML numeric character references are decoded by the browser. For example, &#64; represents the @ symbol. A crawler that parses HTML can decode the same text. Do not rely on replacing letters with numeric references to prevent harvesting or promise that it will stop most spam.

Also keep the mailto: scheme. An encoded address by itself in an href does not become an email link merely because it contains an @ symbol; it may be interpreted as a relative web address.

For a public website, use a dedicated contact inbox or alias that you can manage separately from a private address. Enable the mail provider’s spam filtering and review legitimate messages that may be caught by it. These measures help manage incoming mail; they do not make a published address secret.

Choose between an email link and a contact form

A mailto link is simple and lets visitors use their own email app. A contact form can let visitors write directly on the site and can keep the destination address out of the page markup, provided the server handles delivery. The form needs its own server-side validation and abuse controls; moving the address behind a form does not automatically eliminate spam.

Choose based on the contact experience you need. If you use a form, keep its fields clear and provide useful validation messages. If you use mailto, make the address easy to copy and explain that the link opens the visitor’s email app.

Check the link before publishing

  • Confirm that the recipient is an address you own or are authorised to publish.
  • Inspect the HTML and confirm the mailto: prefix is present.
  • Test the link on desktop and mobile with a configured email handler. Check the recipient, subject, spaces and any body line breaks.
  • Check keyboard access and descriptive link text.
  • Do not treat opening the composer as proof that a message has been delivered.

For more on link semantics and email destinations, see MDN’s anchor-element reference.

Build your HTML and CSS skills

Learn to create clear, usable web pages with Academy Class HTML5 and CSS3 beginner training.

html