Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

How to Add a Contact Form to an Astro Site (No Server Needed)

A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

Tested on Astro 7.4

Cover image for How to Add a Contact Form to an Astro Site (No Server Needed)
In this guide
  1. Step 1: Get an access key
  2. Step 2: Make the page
  3. Step 3: Try it
  4. Add a thank-you page
  5. If spam gets through
  6. Where to go next
  7. Frequently asked questions

A contact form seems simple until you remember what an Astro site is: a folder of files with no computer behind it to receive anything. The fix is a form service. Your form posts to them, they email you. Free, and about ten lines.

Step 1: Get an access key

We’ll use Web3Forms because it needs no account to start. Go to web3forms.com, type the email address that should receive messages, and it sends you an access key. The key is a long string of letters and numbers. It’s safe to put in your page. It only says where messages go.

Formspree works the same way with an account, and its free plan allows 50 messages a month. If you’d rather use it, the form below is almost the same. Swap the action for the address Formspree gives you.

Step 2: Make the page

Create src/pages/contact.astro:

---
import Layout from '../layouts/Layout.astro';
---
<Layout>
  <main>
    <h1>Contact</h1>
    <form action="https://api.web3forms.com/submit" method="POST">
      <input type="hidden" name="access_key" value="YOUR-ACCESS-KEY-HERE" />
      <input type="checkbox" name="botcheck" style="display: none;" tabindex="-1" autocomplete="off" />
      <label>Your name <input type="text" name="name" required /></label>
      <label>Your email <input type="email" name="email" required /></label>
      <label>Message <textarea name="message" required></textarea></label>
      <button type="submit">Send</button>
    </form>
  </main>
</Layout>

Replace YOUR-ACCESS-KEY-HERE with the key from step 1.

Three lines are doing the work:

  • The action is where the form sends its contents. That’s the service.
  • The hidden access_key tells the service which inbox to use.
  • The botcheck box is a honeypot. People never see it, so they never tick it. Bots fill in every field, including this one, and the service throws those away.

Step 3: Try it

Run npm run dev, open localhost:4321/contact, fill in the form, and press Send. The service shows a thank-you page, and the message lands in your inbox within a minute.

We built this page on Astro 7.4 and the form rendered exactly as written. We didn’t send a test message, because that needs a real key tied to a real inbox. Yours will.

Add a thank-you page

Make src/pages/thanks.astro with a short message. Then add this line inside the form:

<input type="hidden" name="redirect" value="https://yoursite.com/thanks/" />

Use your real address. After sending, people land on your own page instead of the service’s.

If spam gets through

The honeypot stops most bots. If some still arrive, both services support a captcha. Web3Forms works with hCaptcha and Cloudflare Turnstile. It’s a few more lines and their docs show them. Turn it on only if you need it. Every extra step loses a few real messages.

Where to go next

  • How to start a newsletter, which uses the same idea: a form that posts to a service.
  • Astro Actions, in Astro’s docs, for when you’re ready to handle forms with your own code on a server.

Frequently asked questions

Why can't my Astro form just send me an email?

An Astro site is a folder of files. Files can't send email. A form service receives the message and emails it to you. Web3Forms and Formspree both do this for free.

Will I get spam?

Some. The hidden honeypot field in this guide catches most bots. If more gets through, both services offer a captcha you can switch on.

Can I style the form?

Yes. It's normal HTML, so your site's CSS applies to it like anything else.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astrobeginner.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add Search to an Astro Site With Pagefind

    Pagefind gives your static Astro site a real search box in about ten minutes, with no server and no monthly fee. It's what AstroBeginner uses.

    Tutorials, 8 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".