Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Write an Email Address as a Link in HTML

· 4 min read · Home Tech

In this article
  1. The Basic Structure of a Mailto Link
  2. Checklist Before You Start
  3. Step-by-Step Guide to Creating the Link
  4. Adding Subject Lines and Body Text
  5. Worked Example: Contact Form Alternative
  6. Common Mistakes That Break Links
  7. Security and Spam Considerations
  8. Testing Your Link
  9. Frequently Asked Questions

Write an email address as a link using the mailto: protocol inside an anchor tag. The code looks like this: <a href="mailto:email@example.com">Send Email</a>.

Time 5 min · Steps 3 · Level Easy

An email link uses the standard HTML anchor tag but replaces the web address with a special prefix called a URI scheme. This tells the browser to open the default mail client instead of loading a webpage. You place the word "mailto:" immediately before the email address, with no spaces between them.

This method works for any website or blog platform that allows raw HTML input. It is the most reliable way to let visitors contact you directly without exposing your address to simple scraping bots. However, it only works if the visitor has a configured email app on their device.

Checklist Before You Start

  • Verify your email address: Ensure the address you want to link to is active and monitored.
  • Choose your display text: Decide what users will see (e.g., "Contact Us" vs. the actual email).
  • Open your HTML editor: Have access to the source code or a custom HTML block in your CMS.
  1. Start the anchor tag: Type <a followed by a space. Add the attribute href= and open a double quote mark.
  2. Add the mailto protocol: Type mailto: immediately after the opening quote. Do not add a space here.
  3. Type the email address: Enter the full email address (e.g., user@example.com) right after the colon. Close the double quote.
  4. Add closing bracket: Type > to close the opening tag.
  5. Add visible text: Type the text you want users to click on (e.g., "Email Me").
  6. Close the tag: Type </a> to end the link.

Adding Subject Lines and Body Text

You can pre-fill the subject line and body of the email to guide the recipient. This reduces friction for the user and organizes incoming messages. Use a question mark ? to start the subject line and an ampersand & to separate multiple parameters.

For example, to set a subject, add ?subject=Inquiry after the email address. To add body text, add &body=Hello. Always URL-encode spaces as %20 to ensure compatibility across all browsers.

Worked Example: Contact Form Alternative

Imagine you run a small bakery and want customers to order cakes. Your email is orders@sweetbakery.com. You want the link to say "Order a Cake" and pre-fill the subject with "Cake Inquiry".

The full code would be:

<a href="mailto:orders@sweetbakery.com?subject=Cake%20Inquiry">Order a Cake</a>

When a user clicks this, their email app opens with the address filled in, the subject line ready, and the cursor in the body. They just need to type their request and hit send. This takes about 10 seconds less than filling out a complex form.

Even small errors can prevent the link from working. Here are four specific mistakes and what they cause.

Mistake 1: Adding a Space After 'mailto:'

If you write href="mailto: user@example.com", the space breaks the protocol. Most browsers will try to load a webpage at "user@example.com" instead of opening an email client. Remove the space immediately after the colon.

Mistake 2: Forgetting the Protocol

Writing just href="user@example.com" makes it a broken hyperlink. The browser treats it as a relative file path. Always include mailto: to signal it is an email action.

Mistake 3: Unencoded Spaces in Subject

In ?subject=My Question, the space may cause a 404 error or cut off the subject at "My". Replace spaces with %20 so the string remains continuous. Use ?subject=My%20Question.

Mistake 4: Using Single Quotes Incorrectly

If your display text contains a single quote (e.g., "It's Good"), wrapping the whole href in single quotes causes syntax errors. Use double quotes for the href value, or escape the inner quote.

Security and Spam Considerations

Publishing a mailto: link exposes your address to automated scrapers. These bots scan websites for email patterns and add them to spam lists. To mitigate this, consider obfuscating the address or using a contact form plugin instead.

If you must use the link, keep your personal address private. Use a dedicated business alias like info@ or support@. This allows you to filter spam without losing legitimate inquiries.

Always test the link on both desktop and mobile devices. On desktop, it should open Outlook, Thunderbird, or Apple Mail. On mobile, it should trigger the choice between Gmail, Samsung Mail, or the default iOS Mail app.

Click the link yourself. Verify the subject line appears correctly. Check that the email address is spelled right. If the wrong app opens, check your system settings to set the preferred mail client.

Frequently Asked Questions

Can I add CC or BCC recipients?

Yes. Add &cc=another@email.com or &bcc=secret@email.com to the end of the URL. Separate each parameter with an ampersand. Note that some email clients hide BCC fields by default.

Does this work on all devices?

It works on all modern smartphones and computers. However, it requires a configured email account. If the user has no email app installed, the link may do nothing or show an error message.

Should I hide my real email address?

For public websites, yes. Scrapers target visible mailto: links. Consider using a CAPTCHA-protected contact form for better protection against spam.

Official source: W3C