Mailto Subject & Body URL Encoding Guide
Learn how to use percent encoding (URL encoding) for special characters, spaces, and line breaks in your HTML mailto links.
Why Must You Encode Mailto Parameters?
A mailto link is an internet URL. URLs can only contain a limited set of ASCII characters. When you put spaces, line breaks, or special symbols (like &, ?, or emojis) in the subject or body, they will break the URL structure and prevent the email client from reading the string properly.
To make them safe, they must be converted into Percent Encoding (URL Encoding).
Common Character Encodings
| Character | URL Encoded Value | Usage Scenario |
|---|---|---|
| Space ( ) | %20 | Used to represent standard word spaces. Avoid using '+' in mailto links as some clients print it literally. |
| Line Break (Newline) | %0A | Starts a new line in the email body. Use %0D%0A or just %0A. |
| Ampersand (&) | %26 | Crucial to encode because raw & is interpreted by browsers as a parameter separator. |
| Question Mark (?) | %3F | Separates the primary recipient from query parameters. Must be encoded if used inside text. |
| Percent Symbol (%) | %25 | Must be encoded as it serves as the indicator for percent encoding itself. |
How to Encode in Code
Instead of manually translating every character, standard programming libraries provide robust built-in helpers to generate compliant mailto query strings.
// JavaScript / TypeScript
const subject = encodeURIComponent("Meeting & Presentation");
const body = encodeURIComponent("Hi team,\n\nHere is the plan.");
const mailto = `mailto:[email protected]?subject=${subject}&body=${body}`; # Python
import urllib.parse
subject = urllib.parse.quote("Meeting & Presentation")
body = urllib.parse.quote("Hi team,\n\nHere is the plan.")
mailto = f"mailto:[email protected]?subject={subject}&body={body}"