DEV Community

irishgeoff22
irishgeoff22

Posted on

How To Make an Email Link in HTML

To create an email link in HTML, you can use the <a> (anchor) element with the href attribute set to the "mailto:" URL scheme followed by the email address. Here's the basic HTML code for creating an email link:

<a href="mailto:youremail@example.com">Send an email</a>
Enter fullscreen mode Exit fullscreen mode

Replace "youremail@example.com" with the actual email address you want to link to. You can also add a link text, such as "Send an email," between the opening and closing <a> tags. When a user clicks on the link, it will open their default email client with a new email addressed to the specified email.

Here's an example of a complete HTML document with an email link:

<!DOCTYPE html>
<html>
<head>
    <title>Email Link Example</title>
</head>
<body>
    <p>You can <a href="mailto:youremail@example.com">send me an email</a> for any inquiries.</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

When someone clicks on the "send me an email" link in their web browser, it will prompt them to open their email client and compose a message to the specified email address.

You can also add additional attributes to the anchor element, such as subject and body, to pre-fill the subject and body of the email. Here's an example:

<a href="mailto:youremail@example.com?subject=Question%20for%20You&body=I%20have%20a%20question%20for%20you.">Send an email</a>
Enter fullscreen mode Exit fullscreen mode

In this example, the subject is set to "Question for You," and the body of the email is pre-filled with "I have a question for you." Make sure to URL-encode the subject and body text to handle special characters properly.

PRO TIP: Using this method it is possible that a web scraper can scrape your email address from your site and then send spam messages to that email.

Its best to protect your email address behind a captcha.
You can use the free email to link service https://VeilMail.io to protect your email address and prevent email spam.

Top comments (0)