splitforms.com

Contact form · Astro

Contact form for Astro websites

Astro's zero-JS-by-default philosophy pairs perfectly with the splitforms endpoint. Use a pure HTML form for static pages, an Astro Action for SSR, or a React/Vue/Svelte island for client-side interactivity. Same backend, three patterns, zero hydration cost when you don't need it.

  • 500 free / month
  • One endpoint
  • No backend code
Astro contact form — copy-paste code for splitforms

How do you add a contact form to Astro?

To add a contact form to an Astro site, put a plain <form> in a .astro component with its action set to https://splitforms.com/api/submit and a hidden access_key input. It works on fully static Astro builds with no server adapter or API endpoint, and each submission is spam-filtered, stored and emailed to you. Free for 500 submissions a month.

Key benefits

No backend code

No server, API route, or SDK. Your Astro form posts straight to one endpoint.

Straight to your inbox

Every submission is emailed to you and saved to a searchable dashboard — spam filtered before it reaches you.

Design without limits

It's your own Astro markup and styles. Splitforms is only the backend, so nothing constrains how the form looks.

Copy-paste ready

Your Astro contact form, ready to paste.

Replace YOUR_ACCESS_KEY with the key from your dashboard — that's the whole integration. No SDK to install, no build step, just the astro you already write.

contact.astro
---
const ACCESS_KEY = import.meta.env.PUBLIC_SPLITFORMS_KEY;
---

<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value={ACCESS_KEY} />

  <input type="text"  name="name"    placeholder="Name"  required />
  <input type="email" name="email"   placeholder="Email" required />
  <textarea           name="message" placeholder="Message" required />

  <input type="checkbox" name="botcheck" style="display:none" tabindex="-1" />

  <button type="submit">Send</button>
</form>

How to add it

How to add a contact form to a Astro website.

To add a contact form to a Astro website you need three things: a free splitforms access key, the astro snippet above, and your key pasted into it. No backend, server, or SDK — the form posts to one URL and every submission lands in your inbox and dashboard.

  1. Get your free splitforms access key

    Sign up at splitforms.com, verify your email, and copy your access key from the dashboard. No credit card required.

  2. Drop the Astro snippet into your project

    Copy the Astro code example into your project and replace YOUR_ACCESS_KEY with the key from step 1.

  3. Receive submissions in your dashboard

    Submissions arrive in the splitforms dashboard within seconds. Free includes owner email notification attempts; Pro adds Slack, Discord, Sheets, or any signed webhook URL.

Where submissions go

Where do your Astro form submissions go?

Every submission is emailed to you and saved to a searchable dashboard — spam filtered before it ever reaches you. Search, export to CSV, or forward it to a webhook or Slack on Pro.

  • 500 submissions a month, free to start
  • Honeypot + automatic spam scoring on every plan
  • Signed webhooks to Slack, Discord, your server
Astro contact form submissions in the splitforms dashboard

No backend needed

Do you need a backend for a Astro form? No.

Your Astro form posts standard FormData to one URL. Splitforms validates the access key, runs its spam checks, and forwards it to your email — so there's no server, API route, or database for you to build or maintain.

  • Zero JavaScript shipped — pure HTML form action
  • Works with Astro Islands, SSR, and the new Astro Actions API
  • Pull access key from import.meta.env so it never lands in the bundle
How splitforms processes a Astro form submission

Best practices

What a production-ready Astro form needs.

The difference between a form that works in the demo and one that survives launch traffic — the production-tested defaults, in priority order.

  • Use the pure HTML form pattern (the snippet above) for static pages — zero JS shipped, no hydration cost, works with JavaScript disabled.
  • Set PUBLIC_SPLITFORMS_KEY in .env and reference it in the Astro frontmatter. Lock the key to your domain in the splitforms dashboard so a leaked key can't be replayed.
  • Configure the absolute /thanks URL in Dashboard → Form settings → Redirect so non-JS users still land on a thank-you page after submitting.
Production-ready Astro contact form best practices

Questions

Astro contact form questions.

Anything missing? Email us, we read every message.

A person reading answers to common questions
How do I add a contact form to Astro?

Paste the snippet above into any .astro page or component. Set PUBLIC_SPLITFORMS_KEY in your .env file. That's it — no install, no astro:integrations, no adapter changes.

Does splitforms work with Astro SSR and SSG?

Yes — both. In SSG (output: 'static') the form posts directly to splitforms.com from the browser. In SSR (output: 'server' or 'hybrid') you can additionally use Astro Actions to keep the key server-side. Pick whichever fits.

How do I handle form errors in Astro?

If you're using Astro Actions, render result?.error?.message from Astro.getActionResult(actions.contact). A pure HTML submission uses splitforms's built-in error page; use fetch or an Astro Action when you need a custom inline error state.

Can I use splitforms with Astro Islands (React, Vue, Svelte, Solid)?

Yes. Build the form as a React/Vue/Svelte component, hydrate with client:visible or client:idle, and use the framework-specific snippet from the matching /forms/<framework> page.

How do I customize the success / redirect behavior?

Add a hidden redirect field pointing at /thanks for a native POST — splitforms sends the browser there after success, free on every plan — or set a default in Dashboard → Form settings → Redirect for when no hidden field is present. With Astro Actions, render success state from result.data or navigate in your action instead.

Will splitforms add 1KB of JS to my Astro site?

No. The default snippet uses zero JavaScript — it's a vanilla <form action method=POST>. JavaScript only runs if you choose the island pattern or wire up custom client-side validation.

Show 8 more questions
PUBLIC_ prefix is required for client-exposed env vars

Astro mirrors Vite's env-var convention: only variables prefixed with PUBLIC_ are exposed to client-side code (and to .astro files when output: 'static'). If you write import.meta.env.SPLITFORMS_KEY, you'll get undefined at build time. Rename to PUBLIC_SPLITFORMS_KEY.

client:load on the form island defeats the point of Astro

If you wrap the form in <MyForm client:load />, you ship a full React/Preact runtime just for one form. Use client:visible (load when scrolled into view) or client:idle (load after main thread is free) instead. For zero-JS forms, skip the island entirely and use a plain HTML form action.

Astro Actions need a try/catch or they crash the page

If your action throws, Astro 5's behavior is to render an error page rather than return the error to your form. Wrap the splitforms fetch in try/catch and return { success: false, message } from the action — your form component can then render the message.

View Transitions can break form re-submit state

If you've enabled <ViewTransitions /> in your layout, navigating to /contact and back may re-mount the form mid-submission. Add data-astro-reload to the form's submit anchor or guard with if (status === 'loading') return at the top of your handler.

Adapter mismatch: form posts to /api/submit fail in static mode

If output: 'static' in astro.config.mjs, you can't have a server endpoint at all — your form must POST directly to splitforms.com. That's the recommended setup. Switch to output: 'server' or 'hybrid' only if you genuinely need a server-side proxy.

Frontmatter fence forgotten — form action renders as literal text

Astro requires the --- fence at the top of .astro files for any frontmatter (imports, Astro.props, env reads). If you write const accessKey = import.meta.env.PUBLIC_SPLITFORMS_KEY; without the surrounding fence, Astro treats the line as plain text in the rendered HTML — you'll see the JavaScript leak into the page above your form. The build doesn't error; it just renders nonsense. Always wrap any logic in --- and reference values via {accessKey} in the template body.

How does Astro handle forms without splitforms?

Astro's whole pitch is shipping zero JavaScript by default. A native contact form on Astro means either (a) building a form with no submission target — useless — or (b) standing up an API endpoint via output: 'server' or 'hybrid', which means writing a Node/Bun/Deno handler, picking an email provider, writing your own honeypot logic. Astro 5 added typed Actions, but they're a wrapper around the same underlying fetch — you still deliver the email yourself. The result: every Astro contact-form tutorial ends with 'now configure SendGrid'. Splitforms is the SendGrid-replacement that doesn't require an account, an API key for the email provider, or DNS records for SPF/DKIM.

Any deployment notes for shipping Astro to production?

Astro deploys cleanly to Vercel, Netlify, Cloudflare Pages, GitHub Pages, and any static host with output: 'static'. For Astro Actions (Pattern B), you need output: 'server' or 'hybrid' and a matching adapter (@astrojs/vercel, @astrojs/netlify, @astrojs/cloudflare). On Cloudflare Pages with the Cloudflare adapter, the Action runs in a Worker — keep the splitforms fetch tight (no extra proxying) to stay under the 10ms CPU budget on the free plan. The PUBLIC_ prefix is mandatory for env vars exposed to client-rendered .astro files; vars without it are silently undefined. Lock the key to your *.pages.dev and custom domain.

View all FAQs

Ship your Astro contact form in 60 seconds.

Free to start on 500 submissions a month. Need Slack alerts, signed webhooks, or file uploads? Pro unlocks them for $5/mo — so you only pay once you outgrow free.

  • No credit card required
  • 500 free submissions
  • Setup in minutes
Two people celebrating a working contact form