To make a contact form in HTML, use a <form> element with labeled fields for name, email and message, plus a submit button. HTML only builds the form, though. To actually receive messages, the form's action attribute must point to something that processes the data and emails it to you: a script on your web host or a third-party form service.
This guide builds a clean, accessible contact form, explains the attributes that matter, shows the options for making it send, and covers spam and privacy.
The HTML for a basic contact form
Here is a complete form. Each line below is one line of the HTML:
<form action="/contact.php" method="post"><label for="name">Your name</label><input type="text" id="name" name="name" autocomplete="name" required><label for="email">Email address</label><input type="email" id="email" name="email" autocomplete="email" required><label for="message">Message</label><textarea id="message" name="message" rows="6" required></textarea><button type="submit">Send message</button></form>
That is all the HTML a simple contact form needs. The /contact.php address is a placeholder. You will replace it with your real handler in a later step.
What each part does
| Piece | Why it matters |
|---|---|
action | The address the form data is sent to. Without a working handler here, nothing happens. |
method="post" | Sends the data in the body of the request rather than in the URL. Always use post for contact forms. |
name | The label each value is sent under. A field without a name is not sent at all. |
<label for> | Links visible text to a field by its id. Screen readers announce it, and clicking the label focuses the field. |
type="email" | Checks the address looks valid and shows an email keyboard on phones. |
required | Stops the form being submitted while the field is empty. |
autocomplete | Lets browsers fill in the visitor's name and email for them. |
Browser checks such as required and type="email" make the form friendlier, but they are not security. Anyone can bypass them, so the script that receives the data must check it again.
Making the form easy to use
A few small choices make a big difference to how many people complete your form:
- Ask for as little as possible. Name, email and message are usually enough. Every extra field loses some visitors.
- Always use real labels. Placeholder text inside a field disappears as soon as someone types, and it is not a substitute for a label.
- Stack fields in one column. It is easier to follow, especially on phones.
- Make the button say what happens, such as "Send message" rather than "Submit".
- Style it in your stylesheet. Give labels
display: block;, and give inputswidth: 100%;and some padding so they are easy to tap. - Show a clear thank-you message or page after sending, so people know it worked.
For more on labels and keyboard use, see our guide to website accessibility basics.
Making the form actually send
This is where most homemade contact forms fail. HTML has no way to send email by itself. You need something on a server to receive the submitted data and pass it on. There are three common options.
Option 1: Your web host's form script
Many hosting plans include a ready-made form-to-email script, or let you run a small PHP script. Your host's help pages will tell you the address to use in action and which hidden fields it expects, such as the recipient address. This keeps everything on your own hosting.
Option 2: A form service
Form services give you an endpoint URL to paste into the action attribute. They receive the submission, filter spam and email it to you. This works on any host, including ones that only serve static files. Check the service's limits, privacy terms and where it stores data before you choose one.
Option 3: Write your own script
If you are comfortable with a server-side language, you can write the handler yourself. It must check every field, protect against people injecting extra email headers, and send mail through your host's approved method. This is the most flexible option and the one that is easiest to get wrong, so many site owners pick option 1 or 2.
What about mailto links?
Setting action="mailto:you@example.com" or using a plain email link avoids a server, but it depends on the visitor having an email program set up on their device. Many people use webmail and will just see nothing happen. A mailto: link is fine as an extra option beside the form, not as a replacement for it.
Stopping spam
Any public form will attract automated spam. Start with the lightest measures and add more only if you need them:
- Use a handler with built-in filtering. Most form services and many host scripts include it.
- Add a honeypot field. This is an extra input hidden from people with CSS. Bots tend to fill in every field, so your script can discard any submission where it has a value. Give it
tabindex="-1"andautocomplete="off"so keyboard users and browsers skip it. - Check on the server that the email field holds a valid address and the message is not empty.
- Add a CAPTCHA only if spam continues, because it adds effort for real visitors too.
Privacy and testing
A contact form collects personal data, so a little care is needed:
- Publish your site over HTTPS so form data is encrypted on the way to the server.
- Say briefly near the form how you will use the details, and link to your privacy policy if you have one.
- Do not ask for information you do not need.
Before you rely on the form, send several test messages. Check that they arrive, that they do not land in your spam folder, and that the thank-you message appears. Test on a phone as well as a computer.
The easier way: drag in a ready-made contact form
Laying out labels, fields and buttons by hand is fiddly. Apollo Editor, a Windows desktop HTML editor, includes a contact form among its drag-and-drop components.
- Drag a contact form onto the page and edit its fields visually in Design mode.
- Switch to Split or Code mode to set the form's
actionto your host's script or form service. - Style the fields and button with the CSS Style Designer, and check the layout at phone size in Preview.
- HTML validation in Code mode highlights errors such as unclosed tags.
Apollo Editor builds the form itself, so you still need a host script or form service to receive messages. Related guides: HTML basics for beginners and how to upload a website with FTP. You can also see the features.
Frequently asked questions
Why does my HTML form not send emails?
HTML alone cannot send email. The form's action must point to a script on your server or a form service that processes the data.
Can I use a mailto link instead of a form?
You can, but it relies on the visitor having an email program set up, so many visitors will not be able to use it.
How do I stop spam from my contact form?
Use a form service or script with spam filtering, a hidden honeypot field, or a CAPTCHA if spam continues.
