How to add a contact form to an Astro site without a backend
How to add a contact form to an Astro site without a backend Static sites are fast, cheap, and easy to deploy. But they don't have a server to receive form submissions. If you're building a portfolio, landing page, do
How to add a contact form to an Astro site without a backend
Static sites are fast, cheap, and easy to deploy. But they don't have a server to receive form submissions.
If you're building a portfolio, landing page, documentation site, or small business website with Astro, you eventually need a way to handle contact forms without setting up and maintaining your own backend.
In this tutorial, we'll build a working contact form using Web3Forms, then look at some alternatives and their trade-offs.
1. The easiest solution: Web3Forms
Web3Forms lets you submit form data to an endpoint without creating your own server.
Its free plan currently offers a limited monthly submission allowance, making it useful for small projects and personal websites.
Get your access key
Visit Web3Forms and generate an access key.
You don't need to create a traditional backend. The key is used to identify your form submissions.
2. Create the Astro component
Create a file:
src/components/ContactForm.astro
---
---
<form id="contact-form">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
<input type="hidden" name="subject" value="New contact form submission" />
<!-- Honeypot field -->
<input
type="checkbox"
name="botcheck"
class="hidden"
style="display: none;"
tabindex="-1"
autocomplete="off"
/>
<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 rows="5"></textarea>
<button type="submit">Send message</button>
</form>
<p id="form-result" role="status" aria-live="polite"></p>
<script>
const form = document.getElementById('contact-form');
const result = document.getElementById('form-result');
form.addEventListener('submit', async (e) => {
e.preventDefault();
result.textContent = 'Sendingβ¦';
const formData = new FormData(form);
const payload = Object.fromEntries(formData);
try {
const response = await fetch('https://api.web3forms.com/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(payload)
});
const data = await response.json();
if (data.success) {
result.textContent = 'Message sent successfully!';
form.reset();
} else {
result.textContent =
data.message || 'Something went wrong. Please try again.';
}
} catch (error) {
result.textContent = 'Network error. Please try again later.';
}
});
</script>
<style>
.hidden {
display: none;
}
form {
display: flex;
flex-direction: column;
gap: 0.75rem;
max-width: 480px;
}
label {
font-weight: 600;
font-size: 0.9rem;
}
input,
textarea {
padding: 0.6rem 0.8rem;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 1rem;
font-family: inherit;
}
button {
padding: 0.7rem 1.2rem;
border: none;
border-radius: 6px;
background: #0070f3;
color: #fff;
font-weight: 600;
cursor: pointer;
}
button:hover {
filter: brightness(1.1);
}
#form-result {
margin-top: 0.5rem;
font-size: 0.9rem;
}
</style>
Replace YOUR_ACCESS_KEY with the key generated on Web3Forms.
3. Use the component on a page
For example, in src/pages/contact.astro:
---
import ContactForm from '../components/ContactForm.astro';
---
<section>
<h1>Contact us</h1>
<ContactForm />
</section>
That's it. No server-side code is required for this implementation.
4. How it works
The form collects:
- Name
- Message
- Access key
- Subject
When the visitor submits the form:
- JavaScript prevents the default form submission.
- The form data is converted into a JSON payload.
- The payload is sent to the Web3Forms API.
- The response is checked.
- A success or error message is displayed.
The hidden honeypot field can help catch bots that automatically fill out every field.
A few things to keep in mind
- The access key is public in frontend code by design.
- Domain restrictions and additional configuration may be available through the provider.
- Free plans have submission limits.
- File uploads and more advanced spam protection may require paid features.
- For production projects, remember to consider privacy requirements and explain how submitted data is handled.
5. What are the alternatives?
There are several form backend services available. Each has different limits, pricing, integrations, and spam protection options.
| Service | Free plan | Main advantage |
|---|---|---|
| Netlify Forms | Limited/credit-based | Convenient if you're already hosting on Netlify |
| Web3Forms | Free monthly submissions | Simple setup and no traditional backend |
| StaticForms | Free submission allowance | Straightforward integration |
| Formspree | Limited monthly submissions | Mature ecosystem and integrations |
| Formspark | Limited free usage | Simple forms and developer-focused workflow |
| Cloudflare Workers | Generous platform free tier | Maximum control if you build your own endpoint |
Pricing and limits can change, so check the providers' official pricing pages before choosing a service.
Links
6. The problem I'm exploring
While looking at these options, I noticed a recurring pattern:
- Free tiers can be restrictive for projects that start receiving traffic.
- Pricing can increase significantly when additional features are needed.
- Advanced spam protection, integrations, and file uploads are often limited to higher plans.
- Developers sometimes need something much simpler than a full backend.
I'm currently researching a concept for a simpler form backend with a higher free tier and transparent pricing.
No product exists yet β this is a validation experiment.
I'm exploring the idea here:
Form Backend β a simpler form backend for static sites
The concept is focused on a simple endpoint, email or webhook delivery, spam filtering, and a developer-friendly experience.
7. I'd love to hear from other developers
If you use forms on static websites:
- Which form backend are you currently using?
- What frustrates you most about existing services?
- Would a higher free tier and simpler pricing be useful?
- Would you pay around $5β9/month for a service like this?
- Which features matter most: spam filtering, file uploads, webhooks, integrations, or analytics?
I'm interested in real experiences and feedback before deciding whether this concept is worth building.
Disclosure: This post is part of a validation experiment. No product exists yet, no features are available, and the pricing mentioned is hypothetical. The landing page is for research purposes only.
Sources
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.