HTML Email Links: The `mailto:` Protocol

Discover how to create clickable email links that make it easy for users to contact you, right from your webpage.

Lesson ProgressStep 1 of 8
0 EXP

Hello! Let's learn how to create a link that opens a user's email client. It all starts with the anchor `<a>` tag.

The Basic 'mailto:' Syntax

To create a clickable email link, you use the standard <a> (anchor) tag. However, instead of an http:// URL in the href attribute, you use the mailto: protocol, followed by the email address.

<a href="mailto:contact@example.com">Email Us!</a>

When a user clicks this link, their default email client (like Apple Mail, Outlook, or Gmail) will open, with the "To" field automatically filled in.

System Check

What protocol prefix must be used in the `href` attribute to create an email link?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

📧
Link Creator

Construct a basic, valid mailto link.

⚙️
Parameter Master

Add subject and body parameters to a mailto link.

🔐
Encoding Expert

Correctly URL-encode a complex mailto link.

Mission: Build a Complex Email Link

Create an email link to "help@support.com" with the subject "Support Request" and the body "I need help with...". Make sure to encode the spaces! The link text should be "Contact Support".

A.D.A. Feedback:

> Awaiting input...

Challenge: Assemble the Link

Drag the components into the correct order to build a valid `mailto` link with a subject.

?subject=My%20Subject
<a href="mailto:user@domain.com
">Click Here</a>

Challenge: Complete the Syntax

Fill in the missing characters to add both a `subject` and a `body` to this link.

<a href="mailto:test@test.comsubject=Hibody=Message">...</a>

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Complex Email Link" project for feedback from other Net-Runners.

Beyond the Click: The Deep Dive into `mailto:` Links

The mailto: protocol is a simple yet powerful HTML feature that bridges the gap between a static webpage and a user's email client. While a basic link is easy to create, mastering its parameters, encoding, and understanding its limitations is essential for professional web development. This article explores everything you need to know about creating robust and user-friendly email links.

1. The Full Anatomy of a `mailto:` Link

A mailto: link can range from incredibly simple to quite complex. Let's break down its components:

<a href="mailto:to@example.com?cc=cc@example.com&bcc=bcc@example.com&subject=My%20Subject&body=My%20Body%0AWith%20Newline">...</a>
  • mailto:: The protocol that tells the browser to open an email client.
  • to@example.com: The primary recipient. You can add multiple primary recipients by separating them with a comma (email1@example.com,email2@example.com).
  • ?: The query separator. This character signifies the end of the recipient(s) and the beginning of the parameters. It is only used once.
  • &: The parameter separator. This character is used to separate all subsequent parameters from each other.

2. The Complete Parameter List

You can pre-fill almost any part of an email using these standard parameters:

  • subject=...: Sets the subject line of the email.
  • body=...: Sets the main content (body) of the email.
  • cc=...: Sets the "Carbon Copy" recipients. Multiple recipients are comma-separated.
  • bcc=...: Sets the "Blind Carbon Copy" recipients. Multiple recipients are comma-separated.

3. The Art of URL Encoding (Percent-Encoding)

This is the most critical and often overlooked part of creating mailto: links. URLs (and by extension, `href` attributes) can only contain a specific set of "safe" characters. Characters like spaces, line breaks, question marks, and ampersands must be encoded to prevent the link from breaking or being misinterpreted.

This process is called Percent-Encoding because it replaces the special character with a % symbol followed by its hexadecimal ASCII value.

CharacterEncoded ValueMeaning
Space%20A standard space
Line Break%0ANewline (Line Feed). Use this to create line breaks in the `body`.
?%3FUse this if you need a literal `?` in your subject or body.
&%26Use this if you need a literal `&` in your subject or body.

Example: To create a body with "Hello,
How are you?", you would write:
body=Hello,%0AHow%20are%20you%3F

4. The Security vs. Convenience Trade-off

mailto: links are incredibly convenient for users. However, they come with one major drawback: email harvesting. Malicious bots (spam bots) crawl the web looking for the `mailto:` protocol and scrape the email addresses to send spam.

Some developers try to "obfuscate" the email using JavaScript or character entities, but these methods are often easily defeated by modern bots and can harm accessibility for users with screen readers.

✔️ Good Use Case

A personal portfolio or small blog where direct, simple contact is desired and a complex backend is overkill.

❌ Bad Use Case

A large e-commerce site or corporate "Contact Us" page. The high volume of spam and the need to track inquiries make this a poor choice.

Key Takeaway: Use mailto: for its convenience on simple sites, but always URL-encode your parameters. For any business-critical application, a server-side contact form (which hides your email address from the public) is the more secure and professional solution.

`mailto:` Link Glossary

mailto:
The protocol prefix used in an `href` attribute. It instructs the browser to open the user's default email client instead of navigating to a webpage.
Parameter
A key/value pair (e.g., `subject=Hello`) that provides additional information to the `mailto:` link, such as pre-filling the subject or body.
?
Query Separator. The special character used exactly once after the email address(es) to signal the beginning of the parameters.
&
Parameter Separator. The special character used to separate multiple parameters from each other (e.g., between `subject` and `body`).
subject=...
A parameter used to pre-fill the email's subject line.
body=...
A parameter used to pre-fill the main content (body) of the email.
cc=... / bcc=...
Parameters to add "carbon copy" and "blind carbon copy" email recipients. Multiple recipients can be added, separated by commas.
URL Encoding (Percent-Encoding)
The process of converting special characters (like spaces, line breaks, or `?`) into a format that can be safely transmitted in a URL. This is done by replacing the character with a `%` followed by its hex code.
%20
The URL-encoded value for a space.
%0A
The URL-encoded value for a line break (Line Feed). Used to create new lines in the `body` parameter.
Email Harvesting (Scraping)
The process by which automated bots crawl websites, extract `mailto:` links, and add the email addresses to spam lists. This is the primary security risk of using `mailto:`.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications (RFC 6068) and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!