Generate contact form HTML code
Choose the fields your form needs, set the action, and copy the generated markup into your page. The output uses associated labels, native input types, and required attributes so it works without a JavaScript framework.
Use a POST action when a server or form backend will process submissions. Use mailto only for a quick prototype because it depends on the visitor having an email application configured.
The generator creates the form structure. Add your own CSS or target the included class names to match the surrounding website.
Contact form HTML code example
This is the smallest contact form worth publishing: a name, an email address and a message, each with a label, sent by POST.
<form action="https://example.com/contact" method="post">
<label>
<span>Name *</span>
<input type="text" name="name" required />
</label>
<label>
<span>Email *</span>
<input type="email" name="email" required />
</label>
<label>
<span>Message *</span>
<textarea name="message" rows="5" required></textarea>
</label>
<button type="submit">Send message</button>
</form>| Code | What it does |
|---|---|
| action | The URL that receives the submission. Swap it for your own endpoint or form backend. |
| method="post" | Sends the values in the request body instead of the address bar, which is what you want for personal data. |
| <label> | Ties the visible text to its input, so screen readers announce it and tapping the text focuses the field. |
| type="email" | Checks the format in the browser and shows the email keyboard on phones. |
| name | The key your server receives for each value, such as name, email and message. |
| required | Stops the form being sent while the field is empty. Validate again on the server. |
The generator above builds the same structure with the fields you tick, plus a small stylesheet you can keep or replace.
Connect the HTML form to email or a backend
A browser cannot send a reliable email from HTML alone. Point the form action at your own endpoint or a hosted form backend, then validate and sanitise every submitted value on the server.
Keep the method set to POST for personal data, show a clear success state, and return useful validation errors when a field is missing.
If you do not want to maintain a submission endpoint, build the form in LemForms and embed it on the same page.
Make a contact form accessible and spam-resistant
Keep every visible field label connected to its input, preserve a logical keyboard order, and make error messages specific to the field that needs attention.
Add a hidden honeypot and server-side rate limiting to reduce automated spam. Do not rely on client-side required attributes as the only validation layer.
Test the finished form with a keyboard and at a narrow mobile width before publishing it.
Frequently asked questions
Where do submissions go?
With the mailto: action they open the user's email client. For real server-side delivery, point the action at a form backend like LemForms.
Is the generated HTML accessible?
Yes — labels are correctly associated, required fields are marked, and the markup is keyboard-navigable.
Can I style it?
Yes. The output uses simple class names so any CSS framework (Tailwind, Bootstrap, your own) can target it.
Build the form behind the tool
LemForms is the form builder this tool plugs into — calculations, conditional logic, embeds, webhooks, and a real submissions dashboard. Free to start.
Try LemForms freeMore free tools
- QR Code Form GeneratorPaste a form URL and download a QR code as PNG or SVG. Perfect for events, posters, table tents, and packaging. Free.
- Honeypot Field GeneratorGenerate a hidden honeypot field that blocks 90%+ of form spam bots — no CAPTCHA, no user friction, no third-party scripts.
- Form Embed Code GeneratorPaste any form URL and get copy-paste embed code for WordPress, Webflow, Framer, Wix, Squarespace, Shopify, Notion and more.
- NPS Score CalculatorCalculate your Net Promoter Score in seconds. Enter promoters, passives, and detractors — get NPS, percentage breakdown, and industry context.