How to Link an Email in HTML
You’ll want to be able to create email links in HTML. The main reason is that it lets your users directly open their default mail program with the recipient’s address pre-filled. Obviously that’s a better user experience than manually opening their email client and copy-pasting and address.
This post shows you how to set them up.
How do you create a basic email link in HTML?
To link an email address in HTML, use the <a>
tag with the href
attribute, followed by mailto:
and the desired email address. Here's an example:
<a href="mailto:example@example.com">Send Email</a>
How can you add a subject and body to an email link?
You may want to go one step further and include a subject and body text in the link. Your users will certainly thank you for it.
You can pre-fill these fields in the user’s email client by appending the query parameters subject
and body
to the email address in the href
attribute. Use ?
for the first query parameter and &
for any additional ones:
<a href="mailto:example@example.com?subject=Feedback&body=Hi there,">Send Feedback</a>
How do you handle special characters in email links?
When adding a subject or body text with spaces or special characters, URL-encode these characters to ensure the link functions correctly. For instance, encode spaces as %20
. This ensures that your email links are universally functional and error-free:
<a href="mailto:example@example.com?subject=Site%20Feedback&body=I%20wanted%20to%20share%20some%20feedback.">Send Site Feedback</a>
The main reason you’ll want to properly encode special characters in your email links is to make sure they work seamlessly across platforms.
What are the best practices for using email links?
- Choose descriptive anchor text for your email links to enhance both user experience and accessibility.
- Keep in mind that not all users have a default email client set up, which might prevent the mailto link from functioning as expected.
- To prevent spam, think about obfuscating email addresses when using mailto links extensively on your site, or alternatively, employ forms for collecting user feedback.
By understanding how to link an email address in HTML and how to link to an email address in HTML with additional parameters, you’ll let users communicate with ease, directly from your website. This functionality significantly improves the user's interaction with your site, making communication straightforward and effective.
Invite only
We're building the next generation of data visualization.
How to Center a Table in HTML with CSS
Jeremy Sarchet
Adjusting HTML Table Column Width for Better Design
Robert Cooper
How to Link Multiple CSS Stylesheets in HTML
Robert Cooper
Mastering HTML Table Inline Styling: A Guide
Max Musing
HTML Multiple Style Attributes: A Quick Guide
Max Musing
How to Set HTML Table Width for Responsive Design
Max Musing