In this section of our HTML tutorial, we will explore how to create links to email addresses using the <a>
element. This allows users to send emails directly by clicking on the link. We’ll also discuss best practices for publishing email addresses on the internet.
Introduction to Email Links
Email links are a convenient way to let website visitors contact you or your organization with just a single click. Using the <a>
element and the “mailto:” scheme, you can create email links that open the user’s default email client with a pre-filled recipient address. Here’s how to do it.
Basic Syntax
Here is the basic syntax for creating an email link with the <a>
element in HTML:
1 |
<a href="mailto:email@example.com">Email Me</a> |
mailto:
: The “mailto” scheme indicates that the link is an email link.email@example.com
: Replace this with the recipient’s email address.Email Me
: This is the link text that users click on to send an email.
Creating Email Links
To create an email link, you simply use the “mailto:” scheme and specify the recipient’s email address. Here’s an example:
1 |
<a href="mailto:contact@example.com">Contact Us</a> |
When a user clicks this link, it will open their default email client with “contact@example.com” pre-filled in the recipient field.
Best Practices for Publishing Email Addresses
When publishing email addresses on the internet, it’s important to consider best practices to protect against email harvesting by spammers. Here are some tips:
- Use Contact Forms: Instead of displaying email addresses directly on your website, consider using contact forms. This allows users to send messages without exposing the email address.
- Obfuscate Email Addresses: If you must display email addresses, obfuscate them. For example, write “email [at] example [dot] com” or use JavaScript to dynamically generate the email address.
- Avoid Plain Text: Avoid placing email addresses as plain text in images or documents. Spammers can still extract text from images.
- Use JavaScript: You can use JavaScript to dynamically generate email addresses on the page, making it harder for automated email scrapers to collect them.
Code Examples
Here are examples of creating email links in HTML:
Basic Email Link:
1 |
<a href="mailto:info@example.com">Email Us</a> |
Obfuscated Email Link:
1 |
<p>Contact us at: <a href="mailto:contact@example.com">Email</a></p> |
Conclusion
Creating email links in your web content is a user-friendly way to encourage communication and feedback. By using the <a>
element with the “mailto:” scheme, you can create links that open email clients with pre-filled recipient addresses. However, it’s essential to follow best practices when publishing email addresses on the internet to protect against spam and email harvesting. Using contact forms, obfuscating email addresses, and avoiding plain text in images are effective ways to maintain the privacy and security of email addresses while providing a means for users to get in touch.