Add a Contact Form to Astro
Add a zero-JS contact form to an Astro static site with no SSR adapter or API endpoint. Submissions arrive by email, with spam protection built in.
- Create a free W3Forms account and a form. Copy the access key shown once.
- Optional: in Form → Settings, list your site under Allowed domains, so posts from other sites are marked as spam. Include the port when testing locally (for example
localhost:5500). - Paste the markup below. Replace
YOUR_ACCESS_KEYwith your key. - Submit a test. Check the dashboard inbox and your notification email.
Astro ships zero JavaScript by default, so a plain HTML form is ideal. No SSR adapter and no API route — the browser posts straight to W3Forms.
ContactForm.astro
---
// src/components/ContactForm.astro
---
<form action="https://api.w3forms.com/submit" method="POST">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
<label for="name">Name</label>
<input type="text" id="name" name="name" required />
<label for="email">Email</label>
<input type="email" id="email" name="email" required />
<label for="message">Message</label>
<textarea id="message" name="message" required></textarea>
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off"
aria-hidden="true" style="position:absolute;left:-9999px" />
<button type="submit">Send</button>
</form>Next steps
- Generate a correct honeypot
- Validate your form HTML
- Configure redirects and spam settings
- Add a signed webhook
- Compare W3Forms to Formspree & others